2008-09-15 19:42:11 +00:00
|
|
|
|
2008-09-07 21:28:20 +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.Windows;
|
|
|
|
using CodeImp.DoomBuilder.IO;
|
|
|
|
using CodeImp.DoomBuilder.Map;
|
|
|
|
using CodeImp.DoomBuilder.Rendering;
|
|
|
|
using CodeImp.DoomBuilder.Geometry;
|
|
|
|
using CodeImp.DoomBuilder.Editing;
|
|
|
|
using CodeImp.DoomBuilder.Actions;
|
|
|
|
using CodeImp.DoomBuilder.Types;
|
|
|
|
using CodeImp.DoomBuilder.Config;
|
|
|
|
using System.Drawing;
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
namespace CodeImp.DoomBuilder.BuilderModes
|
|
|
|
{
|
|
|
|
[EditMode(DisplayName = "Edit Selection",
|
|
|
|
SwitchAction = "editselectionmode", // Action name used to switch to this mode
|
2008-09-15 19:42:11 +00:00
|
|
|
Volatile = true)]
|
2008-09-07 21:28:20 +00:00
|
|
|
|
|
|
|
public class EditSelectionMode : ClassicMode
|
|
|
|
{
|
|
|
|
#region ================== Enums
|
|
|
|
|
|
|
|
private enum ModifyMode : int
|
|
|
|
{
|
|
|
|
None,
|
|
|
|
Dragging,
|
2008-09-09 05:52:11 +00:00
|
|
|
Resizing,
|
|
|
|
Rotating
|
2008-09-07 21:28:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
private enum Grip : int
|
|
|
|
{
|
|
|
|
None,
|
|
|
|
Main,
|
|
|
|
SizeN,
|
|
|
|
SizeS,
|
|
|
|
SizeE,
|
|
|
|
SizeW,
|
|
|
|
RotateLT,
|
|
|
|
RotateRT,
|
|
|
|
RotateRB,
|
|
|
|
RotateLB
|
|
|
|
}
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
#region ================== Constants
|
|
|
|
|
|
|
|
private const float GRIP_SIZE = 11.0f;
|
2008-09-15 19:42:11 +00:00
|
|
|
private const float ZERO_SIZE_ADDITION = 20.0f;
|
|
|
|
private const byte RECTANGLE_ALPHA = 60;
|
|
|
|
private const byte EXTENSION_LINE_ALPHA = 200;
|
2008-09-09 12:20:39 +00:00
|
|
|
private readonly Cursor[] RESIZE_CURSORS = { Cursors.SizeNS, Cursors.SizeNWSE, Cursors.SizeWE, Cursors.SizeNESW };
|
2008-09-07 21:28:20 +00:00
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
#region ================== Variables
|
|
|
|
|
2008-09-09 05:52:11 +00:00
|
|
|
// Mode to return to
|
|
|
|
private EditMode basemode;
|
|
|
|
private bool modealreadyswitching = false;
|
|
|
|
|
2008-09-15 19:42:11 +00:00
|
|
|
// Highlighted vertex
|
|
|
|
private Vertex highlighted;
|
|
|
|
private Vector2D highlightedpos;
|
|
|
|
|
2008-09-07 21:28:20 +00:00
|
|
|
// Selection
|
|
|
|
private ICollection<Vertex> selectedvertices;
|
|
|
|
private ICollection<Thing> selectedthings;
|
|
|
|
private List<Vector2D> vertexpos;
|
|
|
|
private List<Vector2D> thingpos;
|
2008-09-09 12:20:39 +00:00
|
|
|
private ICollection<Vertex> unselectedvertices;
|
2008-09-15 19:42:11 +00:00
|
|
|
private ICollection<Linedef> unselectedlines;
|
2008-09-07 21:28:20 +00:00
|
|
|
|
|
|
|
// Modification
|
|
|
|
private float rotation;
|
|
|
|
private Vector2D offset;
|
|
|
|
private Vector2D size;
|
|
|
|
private Vector2D baseoffset;
|
|
|
|
private Vector2D basesize;
|
|
|
|
|
|
|
|
// Modifying Modes
|
|
|
|
private ModifyMode mode;
|
2008-09-15 19:42:11 +00:00
|
|
|
private Vector2D dragoffset;
|
2008-09-07 21:28:20 +00:00
|
|
|
private Vector2D resizefilter;
|
|
|
|
private Vector2D resizevector;
|
2008-09-09 12:20:39 +00:00
|
|
|
private Vector2D edgevector;
|
2008-09-07 21:28:20 +00:00
|
|
|
private Line2D resizeaxis;
|
2008-09-09 05:52:11 +00:00
|
|
|
private int stickcorner;
|
|
|
|
private float rotategripangle;
|
2008-09-07 21:28:20 +00:00
|
|
|
|
|
|
|
// Rectangle components
|
2008-09-09 12:20:39 +00:00
|
|
|
private Vector2D[] originalcorners; // lefttop, righttop, rightbottom, leftbottom
|
2008-09-07 21:28:20 +00:00
|
|
|
private Vector2D[] corners;
|
2008-09-09 05:52:11 +00:00
|
|
|
private FlatVertex[] cornerverts;
|
2008-09-07 21:28:20 +00:00
|
|
|
private RectangleF[] resizegrips; // top, right, bottom, left
|
|
|
|
private RectangleF[] rotategrips; // lefttop, righttop, rightbottom, leftbottom
|
2008-09-09 12:20:39 +00:00
|
|
|
private Line2D extensionline;
|
|
|
|
|
|
|
|
// Options
|
|
|
|
private bool snaptogrid; // SHIFT to toggle
|
|
|
|
private bool snaptonearest; // CTRL to enable
|
2008-09-07 21:28:20 +00:00
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
#region ================== Properties
|
|
|
|
|
2008-09-15 19:42:11 +00:00
|
|
|
// Just keep the base mode button checked
|
|
|
|
public override string EditModeButtonName { get { return basemode.GetType().Name; } }
|
|
|
|
|
2008-09-07 21:28:20 +00:00
|
|
|
#endregion
|
|
|
|
|
|
|
|
#region ================== Constructor / Disposer
|
|
|
|
|
|
|
|
// Constructor
|
|
|
|
public EditSelectionMode()
|
|
|
|
{
|
|
|
|
// Initialize
|
2008-09-09 05:52:11 +00:00
|
|
|
basemode = General.Map.Mode;
|
2008-09-07 21:28:20 +00:00
|
|
|
mode = ModifyMode.None;
|
|
|
|
|
|
|
|
// TEST:
|
2008-09-09 05:52:11 +00:00
|
|
|
rotation = Angle2D.PI2 * 0;// 0.02f;
|
2008-09-07 21:28:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Disposer
|
|
|
|
public override void Dispose()
|
|
|
|
{
|
|
|
|
// Not already disposed?
|
|
|
|
if(!isdisposed)
|
|
|
|
{
|
|
|
|
// Clean up
|
|
|
|
|
|
|
|
// Dispose base
|
|
|
|
base.Dispose();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
#region ================== Events
|
2008-09-15 19:42:11 +00:00
|
|
|
|
2008-09-07 21:28:20 +00:00
|
|
|
// Mode engages
|
|
|
|
public override void OnEngage()
|
|
|
|
{
|
|
|
|
base.OnEngage();
|
|
|
|
|
2008-09-15 19:42:11 +00:00
|
|
|
// Convert geometry selection
|
2008-09-07 21:28:20 +00:00
|
|
|
General.Map.Map.ClearAllMarks();
|
|
|
|
General.Map.Map.MarkSelectedVertices(true, true);
|
|
|
|
General.Map.Map.MarkSelectedThings(true, true);
|
|
|
|
General.Map.Map.MarkSelectedLinedefs(true, true);
|
|
|
|
ICollection<Vertex> verts = General.Map.Map.GetVerticesFromLinesMarks(true);
|
|
|
|
foreach(Vertex v in verts) v.Marked = true;
|
|
|
|
selectedvertices = General.Map.Map.GetMarkedVertices(true);
|
|
|
|
selectedthings = General.Map.Map.GetMarkedThings(true);
|
2008-09-09 12:20:39 +00:00
|
|
|
unselectedvertices = General.Map.Map.GetMarkedVertices(false);
|
2008-09-15 19:42:11 +00:00
|
|
|
|
2008-09-07 21:28:20 +00:00
|
|
|
// Make sure everything is selected so that it turns up red
|
|
|
|
foreach(Vertex v in selectedvertices) v.Selected = true;
|
|
|
|
ICollection<Linedef> markedlines = General.Map.Map.LinedefsFromMarkedVertices(false, true, false);
|
|
|
|
foreach(Linedef l in markedlines) l.Selected = true;
|
2008-09-15 19:42:11 +00:00
|
|
|
unselectedlines = General.Map.Map.LinedefsFromMarkedVertices(true, false, false);
|
2008-09-07 21:28:20 +00:00
|
|
|
|
|
|
|
// Array to keep original coordinates
|
|
|
|
vertexpos = new List<Vector2D>(selectedvertices.Count);
|
|
|
|
thingpos = new List<Vector2D>(selectedthings.Count);
|
|
|
|
|
|
|
|
// A selection must be made!
|
|
|
|
if((selectedvertices.Count > 0) || (selectedthings.Count > 0))
|
|
|
|
{
|
|
|
|
// Initialize offset and size
|
|
|
|
offset.x = float.MaxValue;
|
|
|
|
offset.y = float.MaxValue;
|
|
|
|
Vector2D right;
|
|
|
|
right.x = float.MinValue;
|
|
|
|
right.y = float.MinValue;
|
|
|
|
|
|
|
|
foreach(Vertex v in selectedvertices)
|
|
|
|
{
|
2008-09-15 19:42:11 +00:00
|
|
|
// Find left-top and right-bottom
|
2008-09-07 21:28:20 +00:00
|
|
|
if(v.Position.x < offset.x) offset.x = v.Position.x;
|
|
|
|
if(v.Position.y < offset.y) offset.y = v.Position.y;
|
|
|
|
if(v.Position.x > right.x) right.x = v.Position.x;
|
|
|
|
if(v.Position.y > right.y) right.y = v.Position.y;
|
|
|
|
|
|
|
|
// Keep original coordinates
|
|
|
|
vertexpos.Add(v.Position);
|
|
|
|
}
|
|
|
|
|
|
|
|
foreach(Thing t in selectedthings)
|
|
|
|
{
|
2008-09-15 19:42:11 +00:00
|
|
|
// Find left-top and right-bottom
|
2008-09-07 21:28:20 +00:00
|
|
|
if(t.Position.x < offset.x) offset.x = t.Position.x;
|
|
|
|
if(t.Position.y < offset.y) offset.y = t.Position.y;
|
|
|
|
if(t.Position.x > right.x) right.x = t.Position.x;
|
|
|
|
if(t.Position.y > right.y) right.y = t.Position.y;
|
|
|
|
|
|
|
|
// Keep original coordinates
|
|
|
|
thingpos.Add(t.Position);
|
|
|
|
}
|
2008-09-15 19:42:11 +00:00
|
|
|
|
|
|
|
// Calculate size
|
2008-09-07 21:28:20 +00:00
|
|
|
size = right - offset;
|
2008-09-15 19:42:11 +00:00
|
|
|
|
|
|
|
// If the width of a dimension is zero, add a little
|
|
|
|
if(Math.Abs(size.x) < 1.0f)
|
|
|
|
{
|
|
|
|
size.x += ZERO_SIZE_ADDITION;
|
|
|
|
offset.x -= ZERO_SIZE_ADDITION / 2;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(Math.Abs(size.y) < 1.0f)
|
|
|
|
{
|
|
|
|
size.y += ZERO_SIZE_ADDITION;
|
|
|
|
offset.y -= ZERO_SIZE_ADDITION / 2;
|
|
|
|
}
|
|
|
|
|
2008-09-07 21:28:20 +00:00
|
|
|
basesize = size;
|
|
|
|
baseoffset = offset;
|
|
|
|
|
|
|
|
// Set presentation
|
|
|
|
if(selectedthings.Count > 0)
|
|
|
|
renderer.SetPresentation(Presentation.Things);
|
|
|
|
else
|
|
|
|
renderer.SetPresentation(Presentation.Standard);
|
|
|
|
|
|
|
|
// Update
|
|
|
|
UpdateRectangleComponents();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
General.Interface.DisplayWarning("Please make a selection first!");
|
|
|
|
|
|
|
|
// Cancel now
|
|
|
|
General.Map.CancelMode();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-09-09 05:52:11 +00:00
|
|
|
// Cancel mode
|
|
|
|
public override void OnCancel()
|
|
|
|
{
|
|
|
|
base.OnCancel();
|
|
|
|
|
|
|
|
// Reset geometry in original position
|
|
|
|
int index = 0;
|
|
|
|
foreach(Vertex v in selectedvertices)
|
|
|
|
v.Move(vertexpos[index++]);
|
|
|
|
|
|
|
|
index = 0;
|
|
|
|
foreach(Thing t in selectedthings)
|
|
|
|
t.Move(thingpos[index++]);
|
|
|
|
|
|
|
|
General.Map.Map.Update(true, true);
|
|
|
|
|
|
|
|
// Return to original mode
|
|
|
|
Type mt = basemode.GetType();
|
|
|
|
basemode = (EditMode)Activator.CreateInstance(mt);
|
|
|
|
General.Map.ChangeMode(basemode);
|
|
|
|
}
|
|
|
|
|
|
|
|
// When accepted
|
|
|
|
public override void OnAccept()
|
|
|
|
{
|
|
|
|
base.OnAccept();
|
|
|
|
|
2008-09-15 19:42:11 +00:00
|
|
|
// Anything to do?
|
|
|
|
if((selectedthings.Count > 0) || (selectedvertices.Count > 0))
|
|
|
|
{
|
|
|
|
Cursor.Current = Cursors.AppStarting;
|
2008-09-09 05:52:11 +00:00
|
|
|
|
2008-09-15 19:42:11 +00:00
|
|
|
// Reset geometry in original position
|
|
|
|
int index = 0;
|
|
|
|
foreach(Vertex v in selectedvertices)
|
|
|
|
v.Move(vertexpos[index++]);
|
2008-09-09 05:52:11 +00:00
|
|
|
|
2008-09-15 19:42:11 +00:00
|
|
|
index = 0;
|
|
|
|
foreach(Thing t in selectedthings)
|
|
|
|
t.Move(thingpos[index++]);
|
|
|
|
|
|
|
|
// Make undo
|
|
|
|
General.Map.UndoRedo.CreateUndo("Edit selection", UndoGroup.None, 0);
|
2008-09-09 05:52:11 +00:00
|
|
|
|
2008-09-15 19:42:11 +00:00
|
|
|
// Move geometry to new position
|
|
|
|
UpdateGeometry();
|
|
|
|
General.Map.Map.Update(true, true);
|
|
|
|
|
|
|
|
// Stitch geometry
|
|
|
|
if(snaptonearest) General.Map.Map.StitchGeometry();
|
|
|
|
|
|
|
|
// Snap to map format accuracy
|
|
|
|
General.Map.Map.SnapAllToAccuracy();
|
|
|
|
|
|
|
|
// Update cached values
|
|
|
|
General.Map.Map.Update();
|
|
|
|
|
|
|
|
// Done
|
|
|
|
selectedvertices = new List<Vertex>();
|
|
|
|
selectedthings = new List<Thing>();
|
|
|
|
Cursor.Current = Cursors.Default;
|
|
|
|
General.Map.IsChanged = true;
|
|
|
|
}
|
|
|
|
|
2008-09-09 05:52:11 +00:00
|
|
|
if(!modealreadyswitching)
|
|
|
|
{
|
|
|
|
// Return to original mode
|
|
|
|
Type mt = basemode.GetType();
|
|
|
|
basemode = (EditMode)Activator.CreateInstance(mt);
|
|
|
|
General.Map.ChangeMode(basemode);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-09-07 21:28:20 +00:00
|
|
|
// Mode disengages
|
|
|
|
public override void OnDisengage()
|
|
|
|
{
|
|
|
|
base.OnDisengage();
|
2008-09-09 05:52:11 +00:00
|
|
|
|
|
|
|
// When not cancelled manually, we assume it is accepted
|
|
|
|
if(!cancelled)
|
|
|
|
{
|
|
|
|
modealreadyswitching = true;
|
|
|
|
this.OnAccept();
|
|
|
|
}
|
2008-09-07 21:28:20 +00:00
|
|
|
|
|
|
|
// Hide highlight info
|
|
|
|
General.Interface.HideInfo();
|
|
|
|
General.Interface.SetCursor(Cursors.Default);
|
|
|
|
}
|
|
|
|
|
|
|
|
// This redraws the display
|
|
|
|
public override void OnRedrawDisplay()
|
|
|
|
{
|
|
|
|
UpdateRectangleComponents();
|
|
|
|
|
|
|
|
// Render lines
|
|
|
|
if(renderer.StartPlotter(true))
|
|
|
|
{
|
|
|
|
renderer.PlotLinedefSet(General.Map.Map.Linedefs);
|
|
|
|
renderer.PlotVerticesSet(General.Map.Map.Vertices);
|
2008-09-15 19:42:11 +00:00
|
|
|
if(highlighted != null) renderer.PlotVertex(highlighted, ColorCollection.HIGHLIGHT);
|
2008-09-07 21:28:20 +00:00
|
|
|
renderer.Finish();
|
|
|
|
}
|
|
|
|
|
|
|
|
// Render things
|
|
|
|
if(renderer.StartThings(true))
|
|
|
|
{
|
|
|
|
renderer.RenderThingSet(General.Map.ThingsFilter.HiddenThings, Presentation.THINGS_HIDDEN_ALPHA);
|
|
|
|
renderer.RenderThingSet(General.Map.ThingsFilter.VisibleThings, 1.0f);
|
|
|
|
renderer.Finish();
|
|
|
|
}
|
|
|
|
|
|
|
|
// Render selection
|
|
|
|
if(renderer.StartOverlay(true))
|
|
|
|
{
|
2008-09-09 12:20:39 +00:00
|
|
|
// Rectangle
|
2008-09-15 19:42:11 +00:00
|
|
|
PixelColor rectcolor = General.Colors.Highlight.WithAlpha(RECTANGLE_ALPHA);
|
2008-09-09 05:52:11 +00:00
|
|
|
renderer.RenderGeometry(cornerverts, null, true);
|
2008-09-15 19:55:03 +00:00
|
|
|
renderer.RenderLine(corners[0], corners[1], 4, rectcolor, true);
|
|
|
|
renderer.RenderLine(corners[1], corners[2], 4, rectcolor, true);
|
|
|
|
renderer.RenderLine(corners[2], corners[3], 4, rectcolor, true);
|
|
|
|
renderer.RenderLine(corners[3], corners[0], 4, rectcolor, true);
|
2008-09-09 12:20:39 +00:00
|
|
|
|
|
|
|
// Extension line
|
|
|
|
if(extensionline.GetLengthSq() > 0.0f)
|
2008-09-15 19:42:11 +00:00
|
|
|
renderer.RenderLine(extensionline.v1, extensionline.v2, 1, General.Colors.Indication.WithAlpha(EXTENSION_LINE_ALPHA), true);
|
2008-09-09 12:20:39 +00:00
|
|
|
|
|
|
|
// Grips
|
2008-09-07 21:28:20 +00:00
|
|
|
for(int i = 0; i < 4; i++)
|
|
|
|
{
|
|
|
|
renderer.RenderRectangleFilled(resizegrips[i], General.Colors.Background, true);
|
|
|
|
renderer.RenderRectangle(resizegrips[i], 2, General.Colors.Highlight, true);
|
|
|
|
renderer.RenderRectangleFilled(rotategrips[i], General.Colors.Background, true);
|
|
|
|
renderer.RenderRectangle(rotategrips[i], 2, General.Colors.Indication, true);
|
|
|
|
}
|
2008-09-09 12:20:39 +00:00
|
|
|
|
2008-09-07 21:28:20 +00:00
|
|
|
renderer.Finish();
|
|
|
|
}
|
|
|
|
|
|
|
|
renderer.Present();
|
|
|
|
}
|
|
|
|
|
|
|
|
// Mouse moves
|
|
|
|
public override void OnMouseMove(MouseEventArgs e)
|
|
|
|
{
|
|
|
|
base.OnMouseMove(e);
|
2008-09-15 19:42:11 +00:00
|
|
|
|
2008-09-09 12:20:39 +00:00
|
|
|
Update();
|
2008-09-07 21:28:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Mouse leaves the display
|
|
|
|
public override void OnMouseLeave(EventArgs e)
|
|
|
|
{
|
|
|
|
base.OnMouseLeave(e);
|
|
|
|
|
|
|
|
// Reset cursor
|
|
|
|
General.Interface.SetCursor(Cursors.Default);
|
|
|
|
}
|
|
|
|
|
2008-09-15 19:55:03 +00:00
|
|
|
// When edit button is pressed
|
|
|
|
protected override void OnEdit()
|
|
|
|
{
|
|
|
|
base.OnEdit();
|
|
|
|
OnSelect();
|
|
|
|
}
|
|
|
|
|
|
|
|
// When edit button is released
|
|
|
|
protected override void OnEndEdit()
|
|
|
|
{
|
|
|
|
base.OnEndEdit();
|
|
|
|
OnEndSelect();
|
|
|
|
}
|
|
|
|
|
2008-09-07 21:28:20 +00:00
|
|
|
// When select button is pressed
|
|
|
|
protected override void OnSelect()
|
|
|
|
{
|
|
|
|
base.OnSelect();
|
2008-09-15 19:42:11 +00:00
|
|
|
|
2008-09-09 05:52:11 +00:00
|
|
|
// Used in many cases:
|
|
|
|
Vector2D center = offset + size * 0.5f;
|
|
|
|
Vector2D delta;
|
|
|
|
|
2008-09-07 21:28:20 +00:00
|
|
|
// Check what grip the mouse is over
|
|
|
|
switch(CheckMouseGrip())
|
|
|
|
{
|
|
|
|
// Drag main rectangle
|
|
|
|
case Grip.Main:
|
2008-09-15 19:42:11 +00:00
|
|
|
|
|
|
|
// Find the original position of the highlighted vertex
|
|
|
|
if(highlighted != null)
|
|
|
|
{
|
|
|
|
int index = 0;
|
|
|
|
foreach(Vertex v in selectedvertices)
|
|
|
|
{
|
|
|
|
if(v == highlighted) highlightedpos = vertexpos[index];
|
|
|
|
index++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
dragoffset = mousemappos - offset;
|
2008-09-07 21:28:20 +00:00
|
|
|
mode = ModifyMode.Dragging;
|
|
|
|
break;
|
|
|
|
|
|
|
|
// Resize
|
|
|
|
case Grip.SizeN:
|
|
|
|
|
2008-09-09 05:52:11 +00:00
|
|
|
// The resize vector is a unit vector in the direction of the resize.
|
|
|
|
// We multiply this with the sign of the current size, because the
|
|
|
|
// corners may be reversed when the selection is flipped.
|
|
|
|
resizevector = corners[1] - corners[2];
|
|
|
|
resizevector = resizevector.GetNormal() * Math.Sign(size.y);
|
|
|
|
|
2008-09-09 12:20:39 +00:00
|
|
|
// The edgevector is a vector with length and direction of the edge perpendicular to the resizevector
|
|
|
|
edgevector = corners[1] - corners[0];
|
|
|
|
|
2008-09-07 21:28:20 +00:00
|
|
|
// Make the resize axis. This is a line with the length and direction
|
|
|
|
// of basesize used to calculate the resize percentage.
|
2008-09-09 05:52:11 +00:00
|
|
|
resizeaxis = new Line2D(corners[2], corners[2] + resizevector * basesize.y);
|
|
|
|
|
|
|
|
// Original axis filter
|
|
|
|
resizefilter = new Vector2D(0.0f, 1.0f);
|
|
|
|
|
|
|
|
// This is the corner that must stay in the same position
|
|
|
|
stickcorner = 2;
|
|
|
|
|
2008-09-15 19:42:11 +00:00
|
|
|
Highlight(null);
|
2008-09-09 05:52:11 +00:00
|
|
|
mode = ModifyMode.Resizing;
|
|
|
|
break;
|
|
|
|
|
|
|
|
// Resize
|
|
|
|
case Grip.SizeE:
|
|
|
|
// See description above
|
|
|
|
resizevector = corners[1] - corners[0];
|
|
|
|
resizevector = resizevector.GetNormal() * Math.Sign(size.x);
|
2008-09-09 12:20:39 +00:00
|
|
|
edgevector = corners[1] - corners[2];
|
2008-09-09 05:52:11 +00:00
|
|
|
resizeaxis = new Line2D(corners[0], corners[0] + resizevector * basesize.x);
|
|
|
|
resizefilter = new Vector2D(1.0f, 0.0f);
|
|
|
|
stickcorner = 0;
|
2008-09-15 19:42:11 +00:00
|
|
|
Highlight(null);
|
2008-09-09 05:52:11 +00:00
|
|
|
mode = ModifyMode.Resizing;
|
|
|
|
break;
|
|
|
|
|
|
|
|
// Resize
|
|
|
|
case Grip.SizeS:
|
|
|
|
// See description above
|
2008-09-07 21:28:20 +00:00
|
|
|
resizevector = corners[2] - corners[1];
|
2008-09-09 05:52:11 +00:00
|
|
|
resizevector = resizevector.GetNormal() * Math.Sign(size.y);
|
2008-09-09 12:20:39 +00:00
|
|
|
edgevector = corners[2] - corners[3];
|
2008-09-09 05:52:11 +00:00
|
|
|
resizeaxis = new Line2D(corners[1], corners[1] + resizevector * basesize.y);
|
2008-09-07 21:28:20 +00:00
|
|
|
resizefilter = new Vector2D(0.0f, 1.0f);
|
2008-09-09 05:52:11 +00:00
|
|
|
stickcorner = 0;
|
2008-09-15 19:42:11 +00:00
|
|
|
Highlight(null);
|
2008-09-09 05:52:11 +00:00
|
|
|
mode = ModifyMode.Resizing;
|
|
|
|
break;
|
|
|
|
|
|
|
|
// Resize
|
|
|
|
case Grip.SizeW:
|
|
|
|
// See description above
|
|
|
|
resizevector = corners[0] - corners[1];
|
|
|
|
resizevector = resizevector.GetNormal() * Math.Sign(size.x);
|
2008-09-09 12:20:39 +00:00
|
|
|
edgevector = corners[0] - corners[3];
|
2008-09-09 05:52:11 +00:00
|
|
|
resizeaxis = new Line2D(corners[1], corners[1] + resizevector * basesize.x);
|
|
|
|
resizefilter = new Vector2D(1.0f, 0.0f);
|
|
|
|
stickcorner = 1;
|
2008-09-15 19:42:11 +00:00
|
|
|
Highlight(null);
|
2008-09-07 21:28:20 +00:00
|
|
|
mode = ModifyMode.Resizing;
|
|
|
|
break;
|
|
|
|
|
2008-09-09 05:52:11 +00:00
|
|
|
// Rotate
|
|
|
|
case Grip.RotateLB:
|
|
|
|
delta = corners[3] - center;
|
|
|
|
rotategripangle = delta.GetAngle() - rotation;
|
2008-09-15 19:42:11 +00:00
|
|
|
Highlight(null);
|
2008-09-09 05:52:11 +00:00
|
|
|
mode = ModifyMode.Rotating;
|
|
|
|
break;
|
|
|
|
|
|
|
|
// Rotate
|
|
|
|
case Grip.RotateLT:
|
|
|
|
delta = corners[0] - center;
|
|
|
|
rotategripangle = delta.GetAngle() - rotation;
|
2008-09-15 19:42:11 +00:00
|
|
|
Highlight(null);
|
2008-09-09 05:52:11 +00:00
|
|
|
mode = ModifyMode.Rotating;
|
|
|
|
break;
|
|
|
|
|
|
|
|
// Rotate
|
|
|
|
case Grip.RotateRB:
|
|
|
|
delta = corners[2] - center;
|
|
|
|
rotategripangle = delta.GetAngle() - rotation;
|
2008-09-15 19:42:11 +00:00
|
|
|
Highlight(null);
|
2008-09-09 05:52:11 +00:00
|
|
|
mode = ModifyMode.Rotating;
|
|
|
|
break;
|
|
|
|
|
|
|
|
// Rotate
|
|
|
|
case Grip.RotateRT:
|
|
|
|
delta = corners[1] - center;
|
|
|
|
rotategripangle = delta.GetAngle() - rotation;
|
2008-09-15 19:42:11 +00:00
|
|
|
Highlight(null);
|
2008-09-09 05:52:11 +00:00
|
|
|
mode = ModifyMode.Rotating;
|
|
|
|
break;
|
2008-09-09 23:06:31 +00:00
|
|
|
|
|
|
|
// Outside the selection?
|
|
|
|
default:
|
|
|
|
// Accept and be done with it
|
|
|
|
General.Map.AcceptMode();
|
|
|
|
break;
|
2008-09-07 21:28:20 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// When selected button is released
|
|
|
|
protected override void OnEndSelect()
|
|
|
|
{
|
|
|
|
base.OnEndSelect();
|
|
|
|
|
2008-09-09 12:20:39 +00:00
|
|
|
// Remove extension line
|
|
|
|
extensionline = new Line2D();
|
|
|
|
|
|
|
|
// No modifying mode
|
2008-09-07 21:28:20 +00:00
|
|
|
mode = ModifyMode.None;
|
2008-09-09 12:20:39 +00:00
|
|
|
|
|
|
|
// Redraw
|
|
|
|
General.Interface.RedrawDisplay();
|
2008-09-07 21:28:20 +00:00
|
|
|
}
|
|
|
|
|
2008-09-09 12:20:39 +00:00
|
|
|
// When a key is released
|
|
|
|
public override void OnKeyUp(KeyEventArgs e)
|
|
|
|
{
|
|
|
|
base.OnKeyUp(e);
|
|
|
|
if((snaptogrid != (General.Interface.ShiftState ^ General.Interface.SnapToGrid)) ||
|
|
|
|
(snaptonearest != (General.Interface.CtrlState ^ General.Interface.AutoMerge))) Update();
|
|
|
|
}
|
|
|
|
|
|
|
|
// When a key is pressed
|
|
|
|
public override void OnKeyDown(KeyEventArgs e)
|
|
|
|
{
|
|
|
|
base.OnKeyDown(e);
|
|
|
|
if((snaptogrid != (General.Interface.ShiftState ^ General.Interface.SnapToGrid)) ||
|
|
|
|
(snaptonearest != (General.Interface.CtrlState ^ General.Interface.AutoMerge))) Update();
|
|
|
|
}
|
2008-09-12 05:50:19 +00:00
|
|
|
|
|
|
|
|
2008-09-09 12:20:39 +00:00
|
|
|
|
2008-09-07 21:28:20 +00:00
|
|
|
#endregion
|
|
|
|
|
|
|
|
#region ================== Methods
|
2008-09-12 05:50:19 +00:00
|
|
|
|
|
|
|
// This clears the selection
|
|
|
|
[BeginAction("clearselection", BaseAction = true)]
|
|
|
|
public void ClearSelection()
|
|
|
|
{
|
|
|
|
// Accept changes
|
|
|
|
General.Map.Map.ClearAllSelected();
|
|
|
|
General.Map.AcceptMode();
|
|
|
|
}
|
2008-09-15 19:42:11 +00:00
|
|
|
|
|
|
|
// This highlights a new vertex
|
|
|
|
protected void Highlight(Vertex v)
|
|
|
|
{
|
|
|
|
// Update display
|
|
|
|
if(renderer.StartPlotter(false))
|
|
|
|
{
|
|
|
|
// Undraw previous highlight
|
|
|
|
if((highlighted != null) && !highlighted.IsDisposed)
|
|
|
|
renderer.PlotVertex(highlighted, renderer.DetermineVertexColor(highlighted));
|
|
|
|
|
|
|
|
// Set new highlight
|
|
|
|
highlighted = v;
|
|
|
|
|
|
|
|
// Render highlighted item
|
|
|
|
if((highlighted != null) && !highlighted.IsDisposed)
|
|
|
|
renderer.PlotVertex(highlighted, ColorCollection.HIGHLIGHT);
|
|
|
|
|
|
|
|
// Done
|
|
|
|
renderer.Finish();
|
|
|
|
renderer.Present();
|
|
|
|
}
|
|
|
|
}
|
2008-09-07 21:28:20 +00:00
|
|
|
|
2008-09-09 12:20:39 +00:00
|
|
|
// This updates the selection
|
|
|
|
private void Update()
|
|
|
|
{
|
|
|
|
// Not in any modifying mode?
|
|
|
|
if(mode == ModifyMode.None)
|
|
|
|
{
|
|
|
|
// Check what grip the mouse is over
|
|
|
|
// and change cursor accordingly
|
|
|
|
Grip mousegrip = CheckMouseGrip();
|
|
|
|
switch(mousegrip)
|
|
|
|
{
|
|
|
|
case Grip.Main:
|
2008-09-15 19:55:03 +00:00
|
|
|
|
|
|
|
// Find the nearest vertex within highlight range
|
|
|
|
Vertex v = MapSet.NearestVertex(selectedvertices, mousemappos);
|
|
|
|
|
|
|
|
// Highlight if not the same
|
|
|
|
if(v != highlighted) Highlight(v);
|
|
|
|
|
2008-09-09 12:20:39 +00:00
|
|
|
General.Interface.SetCursor(Cursors.Hand);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case Grip.RotateLB:
|
|
|
|
case Grip.RotateLT:
|
|
|
|
case Grip.RotateRB:
|
|
|
|
case Grip.RotateRT:
|
2008-09-15 19:42:11 +00:00
|
|
|
Highlight(null);
|
2008-09-09 12:20:39 +00:00
|
|
|
General.Interface.SetCursor(Cursors.Cross);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case Grip.SizeE:
|
|
|
|
case Grip.SizeS:
|
|
|
|
case Grip.SizeW:
|
|
|
|
case Grip.SizeN:
|
|
|
|
|
|
|
|
// Pick the best matching cursor depending on rotation and side
|
|
|
|
float resizeangle = rotation;
|
|
|
|
if((mousegrip == Grip.SizeE) || (mousegrip == Grip.SizeW)) resizeangle += Angle2D.PIHALF;
|
|
|
|
resizeangle = Angle2D.Normalized(resizeangle);
|
|
|
|
if(resizeangle > Angle2D.PI) resizeangle -= Angle2D.PI;
|
|
|
|
resizeangle = Math.Abs(resizeangle + Angle2D.PI / 8.000001f);
|
|
|
|
int cursorindex = (int)Math.Floor((resizeangle / Angle2D.PI) * 4.0f) % 4;
|
|
|
|
General.Interface.SetCursor(RESIZE_CURSORS[cursorindex]);
|
2008-09-15 19:42:11 +00:00
|
|
|
Highlight(null);
|
2008-09-09 12:20:39 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
2008-09-15 19:42:11 +00:00
|
|
|
Highlight(null);
|
2008-09-09 12:20:39 +00:00
|
|
|
General.Interface.SetCursor(Cursors.Default);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2008-09-09 17:59:49 +00:00
|
|
|
Vector2D snappedmappos = mousemappos;
|
|
|
|
bool dosnaptogrid = snaptogrid;
|
|
|
|
|
2008-09-09 12:20:39 +00:00
|
|
|
// Options
|
|
|
|
snaptogrid = General.Interface.ShiftState ^ General.Interface.SnapToGrid;
|
|
|
|
snaptonearest = General.Interface.CtrlState ^ General.Interface.AutoMerge;
|
|
|
|
|
|
|
|
// Change to crosshair cursor so we can clearly see around the mouse cursor
|
|
|
|
General.Interface.SetCursor(Cursors.Cross);
|
|
|
|
|
|
|
|
// Check what modifying mode we are in
|
|
|
|
switch(mode)
|
|
|
|
{
|
|
|
|
// Dragging
|
|
|
|
case ModifyMode.Dragging:
|
|
|
|
|
2008-09-15 19:42:11 +00:00
|
|
|
// Change offset without snapping
|
|
|
|
offset = mousemappos - dragoffset;
|
|
|
|
|
|
|
|
// Calculate transformed position of highlighted vertex
|
|
|
|
Vector2D transformedpos = TransformedPoint(highlightedpos);
|
|
|
|
|
|
|
|
// Snap to nearest vertex?
|
|
|
|
if(snaptonearest && (highlighted != null))
|
|
|
|
{
|
|
|
|
float vrange = VerticesMode.VERTEX_HIGHLIGHT_RANGE / renderer.Scale;
|
|
|
|
|
|
|
|
// Try the nearest vertex
|
|
|
|
Vertex nv = MapSet.NearestVertexSquareRange(unselectedvertices, transformedpos, vrange);
|
|
|
|
if(nv != null)
|
|
|
|
{
|
|
|
|
// Change offset to snap to target
|
|
|
|
offset += nv.Position - transformedpos;
|
|
|
|
dosnaptogrid = false;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// Find the nearest unselected line within range
|
|
|
|
Linedef nl = MapSet.NearestLinedefRange(unselectedlines, transformedpos, LinedefsMode.LINEDEF_HIGHLIGHT_RANGE / renderer.Scale);
|
|
|
|
if(nl != null)
|
|
|
|
{
|
|
|
|
// Snap to grid?
|
|
|
|
if(dosnaptogrid)
|
|
|
|
{
|
|
|
|
// Get grid intersection coordinates
|
|
|
|
List<Vector2D> coords = nl.GetGridIntersections();
|
|
|
|
|
|
|
|
// Find nearest grid intersection
|
|
|
|
float found_distance = float.MaxValue;
|
|
|
|
Vector2D found_pos = new Vector2D(float.NaN, float.NaN);
|
|
|
|
foreach(Vector2D v in coords)
|
|
|
|
{
|
|
|
|
Vector2D dist = transformedpos - v;
|
|
|
|
if(dist.GetLengthSq() < found_distance)
|
|
|
|
{
|
|
|
|
// Found a better match
|
|
|
|
found_distance = dist.GetLengthSq();
|
|
|
|
found_pos = v;
|
|
|
|
|
|
|
|
// Do not snap to grid anymore
|
|
|
|
dosnaptogrid = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Found something?
|
|
|
|
if(!float.IsNaN(found_pos.x))
|
|
|
|
{
|
|
|
|
// Change offset to snap to target
|
|
|
|
offset += found_pos - transformedpos;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// Change offset to snap onto the line
|
|
|
|
offset += nl.NearestOnLine(transformedpos) - transformedpos;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Snap to grid?
|
|
|
|
if(dosnaptogrid && (highlighted != null))
|
|
|
|
{
|
|
|
|
// Change offset to align to grid
|
|
|
|
offset += General.Map.Grid.SnappedToGrid(transformedpos) - transformedpos;
|
|
|
|
}
|
2008-09-09 12:20:39 +00:00
|
|
|
|
|
|
|
// Update
|
|
|
|
UpdateGeometry();
|
|
|
|
UpdateRectangleComponents();
|
|
|
|
General.Interface.RedrawDisplay();
|
|
|
|
break;
|
|
|
|
|
|
|
|
// Resizing
|
|
|
|
case ModifyMode.Resizing:
|
|
|
|
|
2008-09-09 17:59:49 +00:00
|
|
|
// Snap to nearest vertex?
|
|
|
|
if(snaptonearest)
|
|
|
|
{
|
|
|
|
float vrange = VerticesMode.VERTEX_HIGHLIGHT_RANGE / renderer.Scale;
|
|
|
|
|
|
|
|
// Try the nearest vertex
|
|
|
|
Vertex nv = MapSet.NearestVertexSquareRange(unselectedvertices, snappedmappos, vrange);
|
|
|
|
if(nv != null)
|
|
|
|
{
|
|
|
|
snappedmappos = nv.Position;
|
|
|
|
dosnaptogrid = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Snap to grid?
|
|
|
|
if(dosnaptogrid)
|
|
|
|
{
|
|
|
|
// Aligned to grid
|
|
|
|
snappedmappos = General.Map.Grid.SnappedToGrid(snappedmappos);
|
|
|
|
}
|
2008-09-09 12:20:39 +00:00
|
|
|
|
|
|
|
// Keep corner position
|
|
|
|
Vector2D oldcorner = corners[stickcorner];
|
|
|
|
|
|
|
|
// Change size with the scale from the ruler
|
|
|
|
float scale = resizeaxis.GetNearestOnLine(snappedmappos);
|
|
|
|
size = (basesize * resizefilter) * scale + size * (1.0f - resizefilter);
|
|
|
|
|
|
|
|
// Adjust corner position
|
|
|
|
Vector2D newcorner = TransformedPoint(originalcorners[stickcorner]);
|
|
|
|
offset -= newcorner - oldcorner;
|
|
|
|
|
|
|
|
// Snappedmappos is outside the edgevector of our rectangle?
|
|
|
|
// Then show the extension line so that the user knows what it is aligning to
|
|
|
|
Vector2D sizefiltered = (size * resizefilter);
|
|
|
|
float sizelength = sizefiltered.x + sizefiltered.y;
|
|
|
|
Line2D edgeline = new Line2D(resizeaxis.v1 + resizevector * sizelength, resizeaxis.v1 + resizevector * sizelength - edgevector);
|
|
|
|
float nearestonedge = edgeline.GetNearestOnLine(snappedmappos);
|
|
|
|
if(nearestonedge > 0.5f)
|
|
|
|
extensionline = new Line2D(edgeline.v1, snappedmappos);
|
|
|
|
else if(nearestonedge < 0.5f)
|
|
|
|
extensionline = new Line2D(edgeline.v2, snappedmappos);
|
|
|
|
|
|
|
|
// Update
|
|
|
|
UpdateGeometry();
|
|
|
|
UpdateRectangleComponents();
|
|
|
|
General.Interface.RedrawDisplay();
|
|
|
|
break;
|
|
|
|
|
|
|
|
// Rotating
|
|
|
|
case ModifyMode.Rotating:
|
|
|
|
|
|
|
|
// Get angle from mouse to center
|
|
|
|
Vector2D center = offset + size * 0.5f;
|
2008-09-09 17:59:49 +00:00
|
|
|
Vector2D delta = snappedmappos - center;
|
2008-09-09 12:20:39 +00:00
|
|
|
rotation = delta.GetAngle() - rotategripangle;
|
|
|
|
|
2008-09-09 17:59:49 +00:00
|
|
|
// Snap rotation to grip?
|
|
|
|
if(dosnaptogrid)
|
|
|
|
{
|
|
|
|
// We make 8 vectors that the rotation can snap to
|
|
|
|
float founddistance = float.MaxValue;
|
|
|
|
float foundrotation = rotation;
|
|
|
|
for(int i = 0; i < 8; i++)
|
|
|
|
{
|
|
|
|
// Make the vectors
|
|
|
|
float angle = (float)i * Angle2D.PI * 0.25f;
|
|
|
|
Vector2D gridvec = Vector2D.FromAngle(angle);
|
|
|
|
Vector3D rotvec = Vector2D.FromAngle(rotation);
|
|
|
|
|
|
|
|
// Check distance
|
|
|
|
float dist = 2.0f - Vector2D.DotProduct(gridvec, rotvec);
|
|
|
|
if(dist < founddistance)
|
|
|
|
{
|
|
|
|
foundrotation = angle;
|
|
|
|
founddistance = dist;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Keep rotation
|
|
|
|
rotation = foundrotation;
|
|
|
|
}
|
|
|
|
|
2008-09-09 12:20:39 +00:00
|
|
|
// Update
|
|
|
|
UpdateGeometry();
|
|
|
|
UpdateRectangleComponents();
|
|
|
|
General.Interface.RedrawDisplay();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-09-07 21:28:20 +00:00
|
|
|
// This checks and returns the grip the mouse pointer is in
|
|
|
|
private Grip CheckMouseGrip()
|
|
|
|
{
|
|
|
|
// Make polygon from corners
|
|
|
|
Polygon rectpoly = new Polygon();
|
|
|
|
rectpoly.AddRange(corners);
|
|
|
|
|
|
|
|
if(PointInRectF(resizegrips[0], mousemappos))
|
|
|
|
return Grip.SizeN;
|
|
|
|
else if(PointInRectF(resizegrips[2], mousemappos))
|
|
|
|
return Grip.SizeS;
|
|
|
|
else if(PointInRectF(resizegrips[1], mousemappos))
|
|
|
|
return Grip.SizeE;
|
|
|
|
else if(PointInRectF(resizegrips[3], mousemappos))
|
|
|
|
return Grip.SizeW;
|
|
|
|
else if(PointInRectF(rotategrips[0], mousemappos))
|
|
|
|
return Grip.RotateLT;
|
|
|
|
else if(PointInRectF(rotategrips[1], mousemappos))
|
|
|
|
return Grip.RotateRT;
|
|
|
|
else if(PointInRectF(rotategrips[2], mousemappos))
|
|
|
|
return Grip.RotateRB;
|
|
|
|
else if(PointInRectF(rotategrips[3], mousemappos))
|
|
|
|
return Grip.RotateLB;
|
|
|
|
else if(rectpoly.Intersect(mousemappos))
|
|
|
|
return Grip.Main;
|
|
|
|
else
|
|
|
|
return Grip.None;
|
|
|
|
}
|
|
|
|
|
|
|
|
// This applies the current rotation and resize to a point
|
|
|
|
private Vector2D TransformedPoint(Vector2D p)
|
|
|
|
{
|
|
|
|
// Resize
|
|
|
|
p = (p - baseoffset) * (size / basesize) + baseoffset;
|
|
|
|
|
2008-09-09 05:52:11 +00:00
|
|
|
// Rotate
|
|
|
|
Vector2D center = baseoffset + size * 0.5f;
|
2008-09-07 21:28:20 +00:00
|
|
|
Vector2D po = p - center;
|
2008-09-09 05:52:11 +00:00
|
|
|
p = po.GetRotated(rotation);
|
2008-09-07 21:28:20 +00:00
|
|
|
p += center;
|
|
|
|
|
2008-09-09 05:52:11 +00:00
|
|
|
// Translate
|
2008-09-07 21:28:20 +00:00
|
|
|
p += offset - baseoffset;
|
|
|
|
|
|
|
|
return p;
|
|
|
|
}
|
|
|
|
|
|
|
|
// This checks if a point is in a rect
|
|
|
|
private bool PointInRectF(RectangleF rect, Vector2D point)
|
|
|
|
{
|
|
|
|
return (point.x >= rect.Left) && (point.x <= rect.Right) && (point.y >= rect.Top) && (point.y <= rect.Bottom);
|
|
|
|
}
|
|
|
|
|
|
|
|
// This moves all things and vertices to match the current transformation
|
|
|
|
private void UpdateGeometry()
|
|
|
|
{
|
|
|
|
int index = 0;
|
|
|
|
foreach(Vertex v in selectedvertices)
|
|
|
|
{
|
|
|
|
v.Move(TransformedPoint(vertexpos[index++]));
|
|
|
|
}
|
|
|
|
|
|
|
|
index = 0;
|
|
|
|
foreach(Thing t in selectedthings)
|
|
|
|
{
|
|
|
|
t.Move(TransformedPoint(thingpos[index++]));
|
|
|
|
}
|
|
|
|
|
|
|
|
General.Map.Map.Update(true, false);
|
|
|
|
}
|
|
|
|
|
|
|
|
// This updates the selection rectangle components
|
|
|
|
private void UpdateRectangleComponents()
|
|
|
|
{
|
|
|
|
float gripsize = GRIP_SIZE / renderer.Scale;
|
2008-09-15 19:42:11 +00:00
|
|
|
PixelColor rectcolor = General.Colors.Highlight.WithAlpha(RECTANGLE_ALPHA);
|
2008-09-07 21:28:20 +00:00
|
|
|
|
2008-09-09 05:52:11 +00:00
|
|
|
// Original (untransformed) corners
|
|
|
|
originalcorners = new Vector2D[4];
|
|
|
|
originalcorners[0] = new Vector2D(baseoffset.x, baseoffset.y);
|
|
|
|
originalcorners[1] = new Vector2D(baseoffset.x + basesize.x, baseoffset.y);
|
|
|
|
originalcorners[2] = new Vector2D(baseoffset.x + basesize.x, baseoffset.y + basesize.y);
|
|
|
|
originalcorners[3] = new Vector2D(baseoffset.x, baseoffset.y + basesize.y);
|
|
|
|
|
2008-09-07 21:28:20 +00:00
|
|
|
// Corners
|
|
|
|
corners = new Vector2D[4];
|
2008-09-09 05:52:11 +00:00
|
|
|
for(int i = 0; i < 4; i++)
|
|
|
|
corners[i] = TransformedPoint(originalcorners[i]);
|
2008-09-07 21:28:20 +00:00
|
|
|
|
2008-09-09 05:52:11 +00:00
|
|
|
// Vertices
|
|
|
|
cornerverts = new FlatVertex[6];
|
|
|
|
for(int i = 0; i < 6; i++)
|
|
|
|
{
|
|
|
|
cornerverts[i] = new FlatVertex();
|
|
|
|
cornerverts[i].z = 1.0f;
|
2008-09-15 19:42:11 +00:00
|
|
|
cornerverts[i].c = rectcolor.ToInt();
|
2008-09-09 05:52:11 +00:00
|
|
|
}
|
|
|
|
cornerverts[0].x = corners[0].x;
|
|
|
|
cornerverts[0].y = corners[0].y;
|
|
|
|
cornerverts[1].x = corners[1].x;
|
|
|
|
cornerverts[1].y = corners[1].y;
|
|
|
|
cornerverts[2].x = corners[2].x;
|
|
|
|
cornerverts[2].y = corners[2].y;
|
|
|
|
cornerverts[3].x = corners[0].x;
|
|
|
|
cornerverts[3].y = corners[0].y;
|
|
|
|
cornerverts[4].x = corners[2].x;
|
|
|
|
cornerverts[4].y = corners[2].y;
|
|
|
|
cornerverts[5].x = corners[3].x;
|
|
|
|
cornerverts[5].y = corners[3].y;
|
|
|
|
|
2008-09-07 21:28:20 +00:00
|
|
|
// Middle points between corners
|
|
|
|
Vector2D middle01 = corners[0] + (corners[1] - corners[0]) * 0.5f;
|
|
|
|
Vector2D middle12 = corners[1] + (corners[2] - corners[1]) * 0.5f;
|
|
|
|
Vector2D middle23 = corners[2] + (corners[3] - corners[2]) * 0.5f;
|
|
|
|
Vector2D middle30 = corners[3] + (corners[0] - corners[3]) * 0.5f;
|
|
|
|
|
|
|
|
// Resize grips
|
|
|
|
resizegrips = new RectangleF[4];
|
|
|
|
resizegrips[0] = new RectangleF(middle01.x - gripsize * 0.5f,
|
|
|
|
middle01.y - gripsize * 0.5f,
|
|
|
|
gripsize, gripsize);
|
|
|
|
resizegrips[1] = new RectangleF(middle12.x - gripsize * 0.5f,
|
|
|
|
middle12.y - gripsize * 0.5f,
|
|
|
|
gripsize, gripsize);
|
|
|
|
resizegrips[2] = new RectangleF(middle23.x - gripsize * 0.5f,
|
|
|
|
middle23.y - gripsize * 0.5f,
|
|
|
|
gripsize, gripsize);
|
|
|
|
resizegrips[3] = new RectangleF(middle30.x - gripsize * 0.5f,
|
|
|
|
middle30.y - gripsize * 0.5f,
|
|
|
|
gripsize, gripsize);
|
|
|
|
|
|
|
|
// Rotate grips
|
|
|
|
rotategrips = new RectangleF[4];
|
|
|
|
rotategrips[0] = new RectangleF(corners[0].x - gripsize * 0.5f,
|
|
|
|
corners[0].y - gripsize * 0.5f,
|
|
|
|
gripsize, gripsize);
|
|
|
|
rotategrips[1] = new RectangleF(corners[1].x - gripsize * 0.5f,
|
|
|
|
corners[1].y - gripsize * 0.5f,
|
|
|
|
gripsize, gripsize);
|
|
|
|
rotategrips[2] = new RectangleF(corners[2].x - gripsize * 0.5f,
|
|
|
|
corners[2].y - gripsize * 0.5f,
|
|
|
|
gripsize, gripsize);
|
|
|
|
rotategrips[3] = new RectangleF(corners[3].x - gripsize * 0.5f,
|
|
|
|
corners[3].y - gripsize * 0.5f,
|
|
|
|
gripsize, gripsize);
|
|
|
|
}
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
}
|
|
|
|
}
|