- generalized geometry dragging into DragGeometryMode

- added dragging mode for linedefs
- deleted old icon resources
This commit is contained in:
codeimp 2008-02-19 18:54:04 +00:00
parent 57d770ffb1
commit a878520a7f
10 changed files with 603 additions and 235 deletions

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.4 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.2 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.7 KiB

View file

@ -12,6 +12,8 @@
<AssemblyName>Builder</AssemblyName>
<StartupObject>CodeImp.DoomBuilder.General</StartupObject>
<ApplicationIcon>Resources\Builder.ico</ApplicationIcon>
<Win32Resource>
</Win32Resource>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|x86' ">
<DebugSymbols>true</DebugSymbols>
@ -372,7 +374,6 @@
</EmbeddedResource>
</ItemGroup>
<ItemGroup>
<Content Include="Resources\Builder.ico" />
<EmbeddedResource Include="Resources\MissingTexture3D.png" />
<None Include="Resources\MissingTexture.png" />
<None Include="Resources\UnknownImage.png" />
@ -486,4 +487,7 @@
<None Include="Resources\Splash2.png" />
<EmbeddedResource Include="Resources\world3d.fx" />
</ItemGroup>
<ItemGroup>
<Content Include="Resources\Builder.ico" />
</ItemGroup>
</Project>

View file

@ -33,6 +33,8 @@
<Reference Include="System.Windows.Forms" />
</ItemGroup>
<ItemGroup>
<Compile Include="LinedefsMode\DragLinedefsMode.cs" />
<Compile Include="Shared\DragGeometryMode.cs" />
<Compile Include="Testing\TriangulatorMode.cs" />
<Compile Include="VisualMode\BaseVisualMode.cs" />
<Compile Include="VisualMode\BaseVisualSector.cs" />

View file

@ -0,0 +1,164 @@
#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]
public class DragLinedefsMode : DragGeometryMode
{
#region ================== Constants
#endregion
#region ================== Variables
private ICollection<Linedef> selectedlines;
private ICollection<Linedef> unselectedlines;
#endregion
#region ================== Properties
#endregion
#region ================== Constructor / Disposer
// Constructor to start dragging immediately
public DragLinedefsMode(EditMode basemode, Linedef dragitem, Vector2D dragstartmappos)
{
// Get the nearest vertex for snapping
Vertex nearest = General.Map.Map.NearestVertex(dragstartmappos);
// Get selected lines
selectedlines = General.Map.Map.GetLinedefsSelection(true);
unselectedlines = General.Map.Map.GetLinedefsSelection(false);
// 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 linedef was selected, deselect it now
if(selectedlines.Count == 1) General.Map.Map.ClearSelectedLinedefs();
}
}
// This redraws the display
public unsafe override void RedrawDisplay()
{
bool viewchanged = false;
// 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
if(CheckViewChanged())
{
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
}
}

View file

@ -297,6 +297,36 @@ namespace CodeImp.DoomBuilder.BuilderModes.Editing
}
}
}
// Mouse wants to drag
protected override void DragStart(MouseEventArgs e)
{
base.DragStart(e);
// Which button is used?
if(e.Button == EditMode.SELECT_BUTTON)
{
// Make selection
}
else if(e.Button == EditMode.EDIT_BUTTON)
{
// Anything highlighted?
if((highlighted != null) && !highlighted.IsDisposed)
{
// Highlighted item not selected?
if(!highlighted.Selected)
{
// Select only this linedef for dragging
General.Map.Map.ClearSelectedLinedefs();
highlighted.Selected = true;
}
// Start dragging the selection
General.Map.ChangeMode(new DragLinedefsMode(new LinedefsMode(), highlighted, mousedownmappos));
}
}
}
#endregion
}

View file

@ -0,0 +1,341 @@
#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
{
public class DragGeometryMode : ClassicMode
{
#region ================== Constants
#endregion
#region ================== Variables
// Mode to return to
private EditMode basemode;
// Mouse position on map where dragging started
private Vector2D dragstartmappos;
// Item used as reference for snapping to the grid
protected Vertex dragitem;
private Vector2D dragitemposition;
// List of old vertex positions
private List<Vector2D> oldpositions;
// List of selected items
private ICollection<Vertex> selectedverts;
// List of non-selected items
private ICollection<Vertex> unselectedverts;
// List of unstable lines
private ICollection<Linedef> unstablelines;
// 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
#endregion
#region ================== Properties
// Just keep the base mode button checked
public override string EditModeButtonName { get { return basemode.GetType().Name; } }
#endregion
#region ================== Constructor / Disposer
// Disposer
public override void Dispose()
{
// Not already disposed?
if(!isdisposed)
{
// Clean up
// Done
base.Dispose();
}
}
#endregion
#region ================== Methods
// Constructor to start dragging immediately
protected void StartDrag(EditMode basemode, Vertex dragitem, Vector2D dragstartmappos, ICollection<Vertex> selected, ICollection<Vertex> unselected)
{
// Initialize
this.dragitem = dragitem;
this.dragstartmappos = dragstartmappos;
this.basemode = basemode;
Cursor.Current = Cursors.AppStarting;
// Make list of selected vertices
selectedverts = selected;
// Make list of non-selected vertices
// This will be used for snapping to nearest items
unselectedverts = unselected;
// Make old positions list
// We will use this as reference to move the vertices, or to move them back on cancel
oldpositions = new List<Vector2D>(selectedverts.Count);
foreach(Vertex v in selectedverts) oldpositions.Add(v.Position);
// Also keep old position of the dragged item
dragitemposition = dragitem.Position;
// Keep view information
lastoffsetx = renderer.OffsetX;
lastoffsety = renderer.OffsetY;
lastscale = renderer.Scale;
// Make list of unstable lines only
// These will have their length displayed during the drag
unstablelines = MapSet.UnstableLinedefsFromVertices(selectedverts);
Cursor.Current = Cursors.Default;
}
// This moves the selected geometry relatively
// Returns true when geometry has actually moved
private bool MoveGeometryRelative(Vector2D offset, bool snapgrid, bool snapnearest)
{
Vector2D oldpos = dragitem.Position;
Vertex nearest;
int i = 0;
// Snap to nearest?
if(snapnearest)
{
// Find nearest unselected item within selection range
nearest = MapSet.NearestVertexSquareRange(unselectedverts, mousemappos, VerticesMode.VERTEX_HIGHLIGHT_RANGE / renderer.Scale);
if(nearest != null)
{
// Move the dragged item
dragitem.Move(nearest.Position);
// Adjust the offset
offset = nearest.Position - dragitemposition;
// Do not snap to grid!
snapgrid = false;
}
}
// Snap to grid?
if(snapgrid)
{
// Move the dragged item
dragitem.Move(dragitemposition + offset);
// Snap item to grid
dragitem.SnapToGrid();
// Adjust the offset
offset += dragitem.Position - (dragitemposition + offset);
}
// Drag item moved?
if(!snapgrid || (dragitem.Position != oldpos))
{
// Move selected geometry
foreach(Vertex v in selectedverts)
{
// Move vertex from old position relative to the
// mouse position change since drag start
v.Move(oldpositions[i] + offset);
// Next
i++;
}
// Moved
return true;
}
else
{
// No changes
return false;
}
}
// Cancelled
public override void Cancel()
{
// Move geometry back to original position
MoveGeometryRelative(new Vector2D(0f, 0f), false, false);
// If only a single vertex was selected, deselect it now
if(selectedverts.Count == 1) General.Map.Map.ClearSelectedVertices();
// Update cached values
General.Map.Map.Update();
// Cancel base class
base.Cancel();
// Return to vertices mode
General.Map.ChangeMode(basemode);
}
// Mode engages
public override void Engage()
{
base.Engage();
}
// Disenagaging
public override void Disengage()
{
base.Disengage();
Cursor.Current = Cursors.AppStarting;
// When not cancelled
if(!cancelled)
{
// Move geometry back to original position
MoveGeometryRelative(new Vector2D(0f, 0f), false, false);
// Make undo for the dragging
General.Map.UndoRedo.CreateUndo("drag vertices", UndoGroup.None, 0, false);
// Move selected geometry to final position
MoveGeometryRelative(mousemappos - dragstartmappos, snaptogrid, snaptonearest);
// Stitch geometry
General.Map.Map.StitchGeometry(selectedverts, unselectedverts);
// Update cached values
General.Map.Map.Update();
// Map is changed
General.Map.IsChanged = true;
}
// Hide highlight info
General.Interface.HideInfo();
// Done
Cursor.Current = Cursors.Default;
}
// This checks if the view offset/zoom changed and updates the check
protected bool CheckViewChanged()
{
bool viewchanged = false;
// 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 updates the dragging
private void Update()
{
snaptogrid = General.Interface.ShiftState ^ General.Interface.SnapToGrid;
snaptonearest = General.Interface.CtrlState;
// Move selected geometry
if(MoveGeometryRelative(mousemappos - dragstartmappos, snaptogrid, snaptonearest))
{
// Update cached values
//General.Map.Map.Update(true, false);
General.Map.Map.Update();
// Redraw
General.Interface.RedrawDisplay();
}
}
// Mouse moving
public override void MouseMove(MouseEventArgs e)
{
base.MouseMove(e);
Update();
}
// Mouse button released
public override void MouseUp(MouseEventArgs e)
{
base.MouseUp(e);
// Is the editing button released?
if(e.Button == EditMode.EDIT_BUTTON)
{
// Just return to vertices mode, geometry will be merged on disengage.
General.Map.ChangeMode(basemode);
}
}
// When a key is released
public override void KeyUp(KeyEventArgs e)
{
base.KeyUp(e);
if(snaptogrid != General.Interface.ShiftState ^ General.Interface.SnapToGrid) Update();
if(snaptonearest != General.Interface.CtrlState) Update();
}
// When a key is pressed
public override void KeyDown(KeyEventArgs e)
{
base.KeyDown(e);
if(snaptogrid != General.Interface.ShiftState ^ General.Interface.SnapToGrid) Update();
if(snaptonearest != General.Interface.CtrlState) Update();
}
#endregion
}
}

View file

@ -42,7 +42,7 @@ namespace CodeImp.DoomBuilder.BuilderModes.Editing
// In that case, just specifying the attribute like this is enough:
[EditMode]
public class DragVerticesMode : ClassicMode
public class DragVerticesMode : DragGeometryMode
{
#region ================== Constants
@ -50,43 +50,12 @@ namespace CodeImp.DoomBuilder.BuilderModes.Editing
#region ================== Variables
// Mode to return to
private EditMode basemode;
// Mouse position on map where dragging started
private Vector2D dragstartmappos;
// Item used as reference for snapping to the grid
private Vertex dragitem;
private Vector2D dragitemposition;
// List of old vertex positions
private List<Vector2D> oldpositions;
// List of selected items
private ICollection<Vertex> selectedverts;
// List of non-selected items
private ICollection<Vertex> unselectedverts;
// List of unstable lines
private ICollection<Linedef> unstablelines;
// 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
#endregion
#region ================== Properties
// Just keep the vertices mode button checked
public override string EditModeButtonName { get { return typeof(VerticesMode).Name; } }
#endregion
@ -95,39 +64,15 @@ namespace CodeImp.DoomBuilder.BuilderModes.Editing
// Constructor to start dragging immediately
public DragVerticesMode(EditMode basemode, Vertex dragitem, Vector2D dragstartmappos)
{
// Initialize
this.dragitem = dragitem;
this.dragstartmappos = dragstartmappos;
this.basemode = basemode;
Cursor.Current = Cursors.AppStarting;
// Make list of selected vertices
// Get selected vertices
selectedverts = General.Map.Map.GetVerticesSelection(true);
// Make list of non-selected vertices
// This will be used for snapping to nearest items
unselectedverts = General.Map.Map.GetVerticesSelection(false);
// Make old positions list
// We will use this as reference to move the vertices, or to move them back on cancel
oldpositions = new List<Vector2D>(selectedverts.Count);
foreach(Vertex v in selectedverts) oldpositions.Add(v.Position);
// Also keep old position of the dragged item
dragitemposition = dragitem.Position;
// Keep view information
lastoffsetx = renderer.OffsetX;
lastoffsety = renderer.OffsetY;
lastscale = renderer.Scale;
// Initialize
base.StartDrag(basemode, dragitem, dragstartmappos,
General.Map.Map.GetVerticesSelection(true),
General.Map.Map.GetVerticesSelection(false));
// Make list of unstable lines only
// These will have their length displayed during the drag
unstablelines = General.Map.Map.LinedefsFromSelectedVertices(false, false, true);
Cursor.Current = Cursors.Default;
// We have no destructor
GC.SuppressFinalize(this);
}
@ -141,95 +86,13 @@ namespace CodeImp.DoomBuilder.BuilderModes.Editing
// Clean up
// Done
isdisposed = true;
base.Dispose();
}
}
#endregion
#region ================== Methods
// This moves the selected geometry relatively
// Returns true when geometry has actually moved
private bool MoveGeometryRelative(Vector2D offset, bool snapgrid, bool snapnearest)
{
Vector2D oldpos = dragitem.Position;
Vertex nearest;
int i = 0;
// Snap to nearest?
if(snapnearest)
{
// Find nearest unselected item within selection range
nearest = MapSet.NearestVertexSquareRange(unselectedverts, mousemappos, VerticesMode.VERTEX_HIGHLIGHT_RANGE / renderer.Scale);
if(nearest != null)
{
// Move the dragged item
dragitem.Move(nearest.Position);
// Adjust the offset
offset = nearest.Position - dragitemposition;
// Do not snap to grid!
snapgrid = false;
}
}
// Snap to grid?
if(snapgrid)
{
// Move the dragged item
dragitem.Move(dragitemposition + offset);
// Snap item to grid
dragitem.SnapToGrid();
// Adjust the offset
offset += dragitem.Position - (dragitemposition + offset);
}
// Drag item moved?
if(!snapgrid || (dragitem.Position != oldpos))
{
// Move selected geometry
foreach(Vertex v in selectedverts)
{
// Move vertex from old position relative to the
// mouse position change since drag start
v.Move(oldpositions[i] + offset);
// Next
i++;
}
// Moved
return true;
}
else
{
// No changes
return false;
}
}
// Cancelled
public override void Cancel()
{
// Move geometry back to original position
MoveGeometryRelative(new Vector2D(0f, 0f), false, false);
// If only a single vertex was selected, deselect it now
if(selectedverts.Count == 1) General.Map.Map.ClearSelectedVertices();
// Update cached values
General.Map.Map.Update();
// Cancel base class
base.Cancel();
// Return to vertices mode
General.Map.ChangeMode(basemode);
}
// Mode engages
public override void Engage()
@ -241,38 +104,13 @@ namespace CodeImp.DoomBuilder.BuilderModes.Editing
public override void Disengage()
{
base.Disengage();
Cursor.Current = Cursors.AppStarting;
// When not cancelled
if(!cancelled)
{
// Move geometry back to original position
MoveGeometryRelative(new Vector2D(0f, 0f), false, false);
// Make undo for the dragging
General.Map.UndoRedo.CreateUndo("drag vertices", UndoGroup.None, 0, false);
// Move selected geometry to final position
MoveGeometryRelative(mousemappos - dragstartmappos, snaptogrid, snaptonearest);
// Stitch geometry
General.Map.Map.StitchGeometry(selectedverts, unselectedverts);
// If only a single vertex was selected, deselect it now
if(selectedverts.Count == 1) General.Map.Map.ClearSelectedVertices();
// Update cached values
General.Map.Map.Update();
// Map is changed
General.Map.IsChanged = true;
}
// Hide highlight info
General.Interface.HideInfo();
// Done
Cursor.Current = Cursors.Default;
}
// This redraws the display
@ -280,11 +118,6 @@ namespace CodeImp.DoomBuilder.BuilderModes.Editing
{
bool viewchanged = false;
// View changed?
if(renderer.OffsetX != lastoffsetx) viewchanged = true;
if(renderer.OffsetY != lastoffsety) viewchanged = true;
if(renderer.Scale != lastscale) viewchanged = true;
// Start rendering
if(renderer.Start(true, viewchanged))
{
@ -302,15 +135,10 @@ namespace CodeImp.DoomBuilder.BuilderModes.Editing
*/
// Redraw things when view changed
if(viewchanged)
if(CheckViewChanged())
{
renderer.SetThingsRenderOrder(false);
renderer.RenderThingSet(General.Map.Map.Things);
// Keep view information
lastoffsetx = renderer.OffsetX;
lastoffsety = renderer.OffsetY;
lastscale = renderer.Scale;
}
// Render lines and vertices
@ -327,60 +155,6 @@ namespace CodeImp.DoomBuilder.BuilderModes.Editing
renderer.Finish();
}
}
// This updates the dragging
private void Update()
{
snaptogrid = General.Interface.ShiftState ^ General.Interface.SnapToGrid;
snaptonearest = General.Interface.CtrlState;
// Move selected geometry
if(MoveGeometryRelative(mousemappos - dragstartmappos, snaptogrid, snaptonearest))
{
// Update cached values
//General.Map.Map.Update(true, false);
General.Map.Map.Update();
// Redraw
General.Interface.RedrawDisplay();
}
}
// Mouse moving
public override void MouseMove(MouseEventArgs e)
{
base.MouseMove(e);
Update();
}
// Mouse button released
public override void MouseUp(MouseEventArgs e)
{
base.MouseUp(e);
// Is the editing button released?
if(e.Button == EditMode.EDIT_BUTTON)
{
// Just return to vertices mode, geometry will be merged on disengage.
General.Map.ChangeMode(basemode);
}
}
// When a key is released
public override void KeyUp(KeyEventArgs e)
{
base.KeyUp(e);
if(snaptogrid != General.Interface.ShiftState ^ General.Interface.SnapToGrid) Update();
if(snaptonearest != General.Interface.CtrlState) Update();
}
// When a key is pressed
public override void KeyDown(KeyEventArgs e)
{
base.KeyDown(e);
if(snaptogrid != General.Interface.ShiftState ^ General.Interface.SnapToGrid) Update();
if(snaptonearest != General.Interface.CtrlState) Update();
}
#endregion
}

View file

@ -431,6 +431,28 @@ namespace CodeImp.DoomBuilder.Map
return list;
}
// Returns a collection of vertices that match a selected state on the linedefs
// The difference with GetVerticesFromLinesSelection is that in this method
// ALL linedefs of a vertex must match the specified selected state.
public ICollection<Vertex> GetVerticesFromLinesSelectionEx(bool selected)
{
List<Vertex> list = new List<Vertex>();
foreach(Vertex v in vertices)
{
bool qualified = true;
foreach(Linedef l in v.Linedefs)
{
if(l.Selected != selected)
{
qualified = false;
break;
}
}
if(qualified) list.Add(v);
}
return list;
}
// Returns a collection of vertices that match a selected state on the linedefs
public ICollection<Vertex> GetVerticesFromSectorsSelection(bool selected)
{
@ -1075,6 +1097,37 @@ namespace CodeImp.DoomBuilder.Map
// Return result
return list;
}
// This makes a list of unstable lines from the given vertices.
// A line is unstable when one vertex is selected and the other isn't.
public static ICollection<Linedef> UnstableLinedefsFromVertices(ICollection<Vertex> verts)
{
Dictionary<Linedef, Linedef> lines = new Dictionary<Linedef, Linedef>();
// Go for all vertices
foreach(Vertex v in verts)
{
// Go for all lines
foreach(Linedef l in v.Linedefs)
{
// If the line exists in the list
if(lines.ContainsKey(l))
{
// Remove it
lines.Remove(l);
}
// Otherwise add it
else
{
// Add the line
lines.Add(l, l);
}
}
}
// Return result
return new List<Linedef>(lines.Values);
}
// This finds the line closest to the specified position
public Linedef NearestLinedef(Vector2D pos) { return MapSet.NearestLinedef(linedefs, pos); }