2014-01-16 09:32:05 +00:00
|
|
|
|
#region ================== Namespaces
|
|
|
|
|
|
|
|
|
|
using System;
|
2012-06-06 13:37:19 +00:00
|
|
|
|
using CodeImp.DoomBuilder.Editing;
|
|
|
|
|
using CodeImp.DoomBuilder.Geometry;
|
|
|
|
|
|
2014-01-16 09:32:05 +00:00
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
namespace CodeImp.DoomBuilder.BuilderModes
|
|
|
|
|
{
|
2013-09-11 09:47:53 +00:00
|
|
|
|
[EditMode(DisplayName = "Draw Ellipse Mode",
|
|
|
|
|
SwitchAction = "drawellipsemode",
|
2014-02-26 14:11:06 +00:00
|
|
|
|
ButtonImage = "DrawEllipseMode.png", //mxd
|
|
|
|
|
ButtonOrder = int.MinValue + 4, //mxd
|
|
|
|
|
ButtonGroup = "000_drawing", //mxd
|
2013-09-11 09:47:53 +00:00
|
|
|
|
AllowCopyPaste = false,
|
|
|
|
|
Volatile = true,
|
|
|
|
|
Optional = false)]
|
|
|
|
|
|
2014-01-16 09:32:05 +00:00
|
|
|
|
public class DrawEllipseMode : DrawRectangleMode
|
|
|
|
|
{
|
|
|
|
|
#region ================== Variables
|
|
|
|
|
|
|
|
|
|
//interface
|
|
|
|
|
private DrawEllipseOptionsPanel panel;
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
#region ================== Constructor
|
2013-03-18 13:52:27 +00:00
|
|
|
|
|
2014-12-03 23:15:26 +00:00
|
|
|
|
public DrawEllipseMode()
|
|
|
|
|
{
|
2013-09-11 09:47:53 +00:00
|
|
|
|
undoName = "Ellipse draw";
|
|
|
|
|
shapeName = "ellipse";
|
2015-07-09 22:32:12 +00:00
|
|
|
|
usefourcardinaldirections = true;
|
2014-01-16 09:32:05 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#endregion
|
2012-06-06 13:37:19 +00:00
|
|
|
|
|
2014-01-16 09:32:05 +00:00
|
|
|
|
#region ================== Settings panel
|
|
|
|
|
|
2014-12-03 23:15:26 +00:00
|
|
|
|
override protected void SetupInterface()
|
|
|
|
|
{
|
2014-01-16 09:32:05 +00:00
|
|
|
|
maxSubdivisions = 512;
|
|
|
|
|
minSubdivisions = 6;
|
|
|
|
|
|
|
|
|
|
//Add options docker
|
|
|
|
|
panel = new DrawEllipseOptionsPanel();
|
|
|
|
|
panel.MaxSubdivisions = maxSubdivisions;
|
|
|
|
|
panel.MinSubdivisions = minSubdivisions;
|
2014-02-28 14:32:20 +00:00
|
|
|
|
panel.MinSpikiness = (int)General.Map.FormatInterface.MinCoordinate;
|
|
|
|
|
panel.MaxSpikiness = (int)General.Map.FormatInterface.MaxCoordinate;
|
2014-01-16 09:32:05 +00:00
|
|
|
|
panel.OnValueChanged += OptionsPanelOnValueChanged;
|
2013-09-11 09:47:53 +00:00
|
|
|
|
}
|
2012-06-06 13:37:19 +00:00
|
|
|
|
|
2014-12-03 23:15:26 +00:00
|
|
|
|
override protected void AddInterface()
|
|
|
|
|
{
|
2014-02-28 14:32:20 +00:00
|
|
|
|
panel.Register();
|
|
|
|
|
bevelWidth = panel.Spikiness;
|
2014-01-16 09:32:05 +00:00
|
|
|
|
subdivisions = panel.Subdivisions;
|
2013-03-18 13:52:27 +00:00
|
|
|
|
}
|
|
|
|
|
|
2014-12-03 23:15:26 +00:00
|
|
|
|
override protected void RemoveInterface()
|
|
|
|
|
{
|
2014-02-28 14:32:20 +00:00
|
|
|
|
panel.Unregister();
|
2014-01-16 09:32:05 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
#region ================== Methods
|
|
|
|
|
|
2014-12-03 23:15:26 +00:00
|
|
|
|
override protected Vector2D[] GetShape(Vector2D pStart, Vector2D pEnd)
|
|
|
|
|
{
|
2013-09-11 09:47:53 +00:00
|
|
|
|
//no shape
|
2015-12-28 15:01:53 +00:00
|
|
|
|
if(pEnd.x == pStart.x && pEnd.y == pStart.y) return new Vector2D[0];
|
2012-06-06 13:37:19 +00:00
|
|
|
|
|
2013-03-18 13:52:27 +00:00
|
|
|
|
//line
|
2014-02-28 14:32:20 +00:00
|
|
|
|
if(pEnd.x == pStart.x || pEnd.y == pStart.y) return new[] { pStart, pEnd };
|
2013-03-18 13:52:27 +00:00
|
|
|
|
|
2013-09-11 09:47:53 +00:00
|
|
|
|
//got shape
|
2015-12-28 15:01:53 +00:00
|
|
|
|
if(bevelWidth < 0)
|
2014-12-03 23:15:26 +00:00
|
|
|
|
{
|
2014-07-02 10:12:53 +00:00
|
|
|
|
currentBevelWidth = -Math.Min(Math.Abs(bevelWidth), Math.Min(width, height) / 2) + 1;
|
2014-12-03 23:15:26 +00:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2014-02-28 14:32:20 +00:00
|
|
|
|
currentBevelWidth = bevelWidth;
|
|
|
|
|
}
|
2012-06-06 13:37:19 +00:00
|
|
|
|
|
2013-09-11 09:47:53 +00:00
|
|
|
|
Vector2D[] shape = new Vector2D[subdivisions + 1];
|
2012-06-06 13:37:19 +00:00
|
|
|
|
|
2013-09-11 09:47:53 +00:00
|
|
|
|
bool doBevel = false;
|
|
|
|
|
int hw = width / 2;
|
|
|
|
|
int hh = height / 2;
|
2012-06-06 13:37:19 +00:00
|
|
|
|
|
2013-09-11 09:47:53 +00:00
|
|
|
|
Vector2D center = new Vector2D(pStart.x + hw, pStart.y + hh);
|
|
|
|
|
float curAngle = 0;
|
|
|
|
|
float angleStep = -Angle2D.PI / subdivisions * 2;
|
2012-06-06 13:37:19 +00:00
|
|
|
|
|
2015-12-28 15:01:53 +00:00
|
|
|
|
for(int i = 0; i < subdivisions; i++)
|
2014-12-03 23:15:26 +00:00
|
|
|
|
{
|
2015-12-28 15:01:53 +00:00
|
|
|
|
int px, py;
|
|
|
|
|
if(doBevel)
|
2014-12-03 23:15:26 +00:00
|
|
|
|
{
|
2013-09-11 09:47:53 +00:00
|
|
|
|
px = (int)(center.x - (float)Math.Sin(curAngle) * (hw + currentBevelWidth));
|
|
|
|
|
py = (int)(center.y - (float)Math.Cos(curAngle) * (hh + currentBevelWidth));
|
2014-12-03 23:15:26 +00:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2013-09-11 09:47:53 +00:00
|
|
|
|
px = (int)(center.x - (float)Math.Sin(curAngle) * hw);
|
|
|
|
|
py = (int)(center.y - (float)Math.Cos(curAngle) * hh);
|
|
|
|
|
}
|
|
|
|
|
doBevel = !doBevel;
|
|
|
|
|
shape[i] = new Vector2D(px, py);
|
|
|
|
|
curAngle += angleStep;
|
|
|
|
|
}
|
|
|
|
|
//add final point
|
|
|
|
|
shape[subdivisions] = shape[0];
|
|
|
|
|
return shape;
|
|
|
|
|
}
|
2012-06-06 13:37:19 +00:00
|
|
|
|
|
2014-12-03 23:15:26 +00:00
|
|
|
|
protected override string GetHintText()
|
|
|
|
|
{
|
2014-07-02 10:12:53 +00:00
|
|
|
|
return "BVL: " + bevelWidth + "; VERTS: " + subdivisions;
|
2013-09-11 09:47:53 +00:00
|
|
|
|
}
|
2012-06-07 01:06:37 +00:00
|
|
|
|
|
2014-01-16 09:32:05 +00:00
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
#region ================== Events
|
|
|
|
|
|
2014-12-03 23:15:26 +00:00
|
|
|
|
private void OptionsPanelOnValueChanged(object sender, EventArgs eventArgs)
|
|
|
|
|
{
|
2014-02-28 14:32:20 +00:00
|
|
|
|
bevelWidth = panel.Spikiness;
|
2014-01-16 09:32:05 +00:00
|
|
|
|
subdivisions = Math.Min(maxSubdivisions, panel.Subdivisions);
|
|
|
|
|
Update();
|
2013-12-11 08:47:11 +00:00
|
|
|
|
}
|
|
|
|
|
|
2014-12-03 23:15:26 +00:00
|
|
|
|
public override void OnHelp()
|
|
|
|
|
{
|
2014-02-10 09:26:13 +00:00
|
|
|
|
General.ShowHelp("/gzdb/features/classic_modes/mode_drawellipse.html");
|
|
|
|
|
}
|
|
|
|
|
|
2014-01-16 09:32:05 +00:00
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
#region ================== Actions
|
|
|
|
|
|
2014-12-03 23:15:26 +00:00
|
|
|
|
override protected void IncreaseSubdivLevel()
|
|
|
|
|
{
|
|
|
|
|
if(maxSubdivisions - subdivisions > 1)
|
|
|
|
|
{
|
2013-09-11 09:47:53 +00:00
|
|
|
|
subdivisions += 2;
|
2014-01-16 09:32:05 +00:00
|
|
|
|
panel.Subdivisions = subdivisions;
|
2013-09-11 09:47:53 +00:00
|
|
|
|
Update();
|
|
|
|
|
}
|
|
|
|
|
}
|
2012-06-06 13:37:19 +00:00
|
|
|
|
|
2014-12-03 23:15:26 +00:00
|
|
|
|
override protected void DecreaseSubdivLevel()
|
|
|
|
|
{
|
2015-12-28 15:01:53 +00:00
|
|
|
|
if(subdivisions - minSubdivisions > 1)
|
2014-12-03 23:15:26 +00:00
|
|
|
|
{
|
2013-09-11 09:47:53 +00:00
|
|
|
|
subdivisions -= 2;
|
2014-01-16 09:32:05 +00:00
|
|
|
|
panel.Subdivisions = subdivisions;
|
|
|
|
|
Update();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2014-12-03 23:15:26 +00:00
|
|
|
|
protected override void IncreaseBevel()
|
|
|
|
|
{
|
|
|
|
|
if(points.Count < 2 || currentBevelWidth == bevelWidth || bevelWidth < 0)
|
|
|
|
|
{
|
2014-02-28 14:32:20 +00:00
|
|
|
|
bevelWidth = Math.Min(bevelWidth + General.Map.Grid.GridSize, panel.MaxSpikiness);
|
|
|
|
|
panel.Spikiness = bevelWidth;
|
2013-09-11 09:47:53 +00:00
|
|
|
|
Update();
|
|
|
|
|
}
|
|
|
|
|
}
|
2014-01-16 09:32:05 +00:00
|
|
|
|
|
2014-12-03 23:15:26 +00:00
|
|
|
|
protected override void DecreaseBevel()
|
|
|
|
|
{
|
|
|
|
|
if(bevelWidth > 0 || currentBevelWidth <= bevelWidth + 1)
|
|
|
|
|
{
|
2014-02-28 14:32:20 +00:00
|
|
|
|
bevelWidth = Math.Max(bevelWidth - General.Map.Grid.GridSize, panel.MinSpikiness);
|
|
|
|
|
panel.Spikiness = bevelWidth;
|
2014-01-16 09:32:05 +00:00
|
|
|
|
Update();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#endregion
|
2013-09-11 09:47:53 +00:00
|
|
|
|
}
|
2012-06-06 13:37:19 +00:00
|
|
|
|
}
|