2014-01-16 09:32:05 +00:00
|
|
|
|
#region ================== Namespaces
|
|
|
|
|
|
|
|
|
|
using System;
|
2016-03-14 10:25:27 +00:00
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using CodeImp.DoomBuilder.Actions;
|
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
|
2016-03-06 20:52:19 +00:00
|
|
|
|
|
2016-02-17 22:23:18 +00:00
|
|
|
|
// Interface
|
2014-01-16 09:32:05 +00:00
|
|
|
|
private DrawEllipseOptionsPanel panel;
|
|
|
|
|
|
2016-03-14 10:25:27 +00:00
|
|
|
|
// Drawing
|
|
|
|
|
private float angle; // in radians
|
|
|
|
|
|
2014-01-16 09:32:05 +00:00
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
#region ================== Constructor
|
2013-03-18 13:52:27 +00:00
|
|
|
|
|
2016-03-14 10:25:27 +00:00
|
|
|
|
public DrawEllipseMode()
|
|
|
|
|
{
|
|
|
|
|
autoclosedrawing = false;
|
|
|
|
|
}
|
|
|
|
|
|
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()
|
|
|
|
|
{
|
2016-02-17 22:23:18 +00:00
|
|
|
|
maxsubdivisions = 512;
|
2016-03-06 20:52:19 +00:00
|
|
|
|
minsubdivisions = 3;
|
|
|
|
|
minpointscount = 3;
|
|
|
|
|
alwaysrendershapehints = true;
|
2014-01-16 09:32:05 +00:00
|
|
|
|
|
2016-03-04 13:41:55 +00:00
|
|
|
|
// Load stored settings
|
|
|
|
|
subdivisions = General.Clamp(General.Settings.ReadPluginSetting("drawellipsemode.subdivisions", 8), minsubdivisions, maxsubdivisions);
|
|
|
|
|
bevelwidth = General.Settings.ReadPluginSetting("drawellipsemode.bevelwidth", 0);
|
2016-03-06 20:52:19 +00:00
|
|
|
|
int angledeg = General.Settings.ReadPluginSetting("drawellipsemode.angle", 0);
|
|
|
|
|
angle = Angle2D.DegToRad(angledeg);
|
2016-03-04 13:41:55 +00:00
|
|
|
|
currentbevelwidth = bevelwidth;
|
|
|
|
|
|
2014-01-16 09:32:05 +00:00
|
|
|
|
//Add options docker
|
|
|
|
|
panel = new DrawEllipseOptionsPanel();
|
2016-02-17 22:23:18 +00:00
|
|
|
|
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;
|
2016-03-04 13:41:55 +00:00
|
|
|
|
panel.Spikiness = bevelwidth;
|
2016-03-06 20:52:19 +00:00
|
|
|
|
panel.Angle = angledeg;
|
2016-03-04 13:41:55 +00:00
|
|
|
|
panel.Subdivisions = subdivisions;
|
2014-01-16 09:32:05 +00:00
|
|
|
|
panel.OnValueChanged += OptionsPanelOnValueChanged;
|
2016-02-17 22:23:18 +00:00
|
|
|
|
panel.OnContinuousDrawingChanged += OnContinuousDrawingChanged;
|
2016-03-04 13:41:55 +00:00
|
|
|
|
|
|
|
|
|
// Needs to be set after adding the OnContinuousDrawingChanged event...
|
|
|
|
|
panel.ContinuousDrawing = General.Settings.ReadPluginSetting("drawellipsemode.continuousdrawing", false);
|
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();
|
2013-03-18 13:52:27 +00:00
|
|
|
|
}
|
|
|
|
|
|
2014-12-03 23:15:26 +00:00
|
|
|
|
override protected void RemoveInterface()
|
|
|
|
|
{
|
2016-03-04 13:41:55 +00:00
|
|
|
|
// Store settings
|
|
|
|
|
General.Settings.WritePluginSetting("drawellipsemode.subdivisions", subdivisions);
|
|
|
|
|
General.Settings.WritePluginSetting("drawellipsemode.bevelwidth", bevelwidth);
|
2016-03-06 20:52:19 +00:00
|
|
|
|
General.Settings.WritePluginSetting("drawellipsemode.angle", panel.Angle);
|
2016-03-04 13:41:55 +00:00
|
|
|
|
General.Settings.WritePluginSetting("drawellipsemode.continuousdrawing", panel.ContinuousDrawing);
|
|
|
|
|
|
|
|
|
|
// Remove the buttons
|
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)
|
|
|
|
|
{
|
2016-03-04 21:21:41 +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
|
|
|
|
|
2016-03-04 21:21:41 +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
|
|
|
|
|
2016-03-04 21:21:41 +00:00
|
|
|
|
// Got shape
|
|
|
|
|
if(subdivisions < 6)
|
|
|
|
|
currentbevelwidth = 0; // Works strange otherwise
|
|
|
|
|
else if(bevelwidth < 0)
|
2016-02-17 22:23:18 +00:00
|
|
|
|
currentbevelwidth = -Math.Min(Math.Abs(bevelwidth), Math.Min(width, height) / 2) + 1;
|
2014-12-03 23:15:26 +00:00
|
|
|
|
else
|
2016-02-17 22:23:18 +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);
|
2016-03-06 20:52:19 +00:00
|
|
|
|
float curAngle = angle;
|
2013-09-11 09:47:53 +00:00
|
|
|
|
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
|
|
|
|
{
|
2016-02-17 22:23:18 +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;
|
|
|
|
|
}
|
2016-03-04 21:21:41 +00:00
|
|
|
|
|
|
|
|
|
// Add final point
|
2013-09-11 09:47:53 +00:00
|
|
|
|
shape[subdivisions] = shape[0];
|
|
|
|
|
return shape;
|
|
|
|
|
}
|
2012-06-06 13:37:19 +00:00
|
|
|
|
|
2016-03-14 10:25:27 +00:00
|
|
|
|
protected override string GetHintText()
|
2014-12-03 23:15:26 +00:00
|
|
|
|
{
|
2016-03-14 10:25:27 +00:00
|
|
|
|
List<string> result = new List<string>();
|
|
|
|
|
if(bevelwidth != 0) result.Add("BVL: " + bevelwidth);
|
|
|
|
|
if(subdivisions != 0) result.Add("VERTS: " + subdivisions);
|
|
|
|
|
if(panel.Angle != 0) result.Add("ANGLE: " + panel.Angle);
|
|
|
|
|
|
|
|
|
|
return string.Join("; ", result.ToArray());
|
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
|
|
|
|
|
|
2016-03-04 21:21:41 +00:00
|
|
|
|
public override void OnAccept()
|
|
|
|
|
{
|
|
|
|
|
switch(points.Count - 1) // Last point matches the first one
|
|
|
|
|
{
|
2016-03-06 20:52:19 +00:00
|
|
|
|
case 3: undoname = "Triangle draw"; shapename = "triangle"; break;
|
2016-03-04 21:21:41 +00:00
|
|
|
|
case 4: undoname = "Rhombus draw"; shapename = "rhombus"; break;
|
|
|
|
|
case 5: undoname = "Pentagon draw"; shapename = "pentagon"; break;
|
|
|
|
|
case 6: undoname = "Hexagon draw"; shapename = "hexagon"; break;
|
|
|
|
|
case 7: undoname = "Heptagon draw"; shapename = "heptagon"; break;
|
|
|
|
|
case 8: undoname = "Octagon draw"; shapename = "octagon"; break;
|
|
|
|
|
case 9: undoname = "Enneagon draw"; shapename = "enneagon"; break;
|
|
|
|
|
case 10: undoname = "Decagon draw"; shapename = "decagon"; break;
|
|
|
|
|
case 11: undoname = "Hendecagon draw"; shapename = "hendecagon"; break;
|
|
|
|
|
case 12: undoname = "Dodecagon draw"; shapename = "dodecagon"; break;
|
|
|
|
|
case 13: undoname = "Tridecagon draw"; shapename = "tridecagon"; break;
|
|
|
|
|
case 14: undoname = "Tetradecagon draw"; shapename = "tetradecagon"; break;
|
|
|
|
|
case 15: undoname = "Pentadecagon draw"; shapename = "pentadecagon"; break;
|
|
|
|
|
case 16: undoname = "Hexadecagon draw"; shapename = "hexadecagon"; break;
|
|
|
|
|
case 17: undoname = "Heptadecagon draw"; shapename = "heptadecagon"; break;
|
|
|
|
|
case 18: undoname = "Octadecagon draw"; shapename = "octadecagon"; break;
|
|
|
|
|
case 19: undoname = "Enneadecagon draw"; shapename = "enneadecagon"; break;
|
|
|
|
|
case 20: undoname = "Icosagon draw"; shapename = "icosagon"; break;
|
|
|
|
|
default: undoname = "Ellipse draw"; shapename = "ellipse"; break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
base.OnAccept();
|
|
|
|
|
}
|
|
|
|
|
|
2014-12-03 23:15:26 +00:00
|
|
|
|
private void OptionsPanelOnValueChanged(object sender, EventArgs eventArgs)
|
|
|
|
|
{
|
2016-02-17 22:23:18 +00:00
|
|
|
|
bevelwidth = panel.Spikiness;
|
|
|
|
|
subdivisions = Math.Min(maxsubdivisions, panel.Subdivisions);
|
2016-03-06 20:52:19 +00:00
|
|
|
|
angle = Angle2D.DegToRad(panel.Angle);
|
2014-01-16 09:32:05 +00:00
|
|
|
|
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()
|
|
|
|
|
{
|
2016-02-17 22:23:18 +00:00
|
|
|
|
if(maxsubdivisions - subdivisions > 1)
|
2014-12-03 23:15:26 +00:00
|
|
|
|
{
|
2016-03-04 21:21:41 +00:00
|
|
|
|
subdivisions += (subdivisions % 2 != 0 ? 1 : 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()
|
|
|
|
|
{
|
2016-02-17 22:23:18 +00:00
|
|
|
|
if(subdivisions - minsubdivisions > 1)
|
2014-12-03 23:15:26 +00:00
|
|
|
|
{
|
2016-03-04 21:21:41 +00:00
|
|
|
|
subdivisions -= (subdivisions % 2 != 0 ? 1 : 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()
|
|
|
|
|
{
|
2016-02-17 22:23:18 +00:00
|
|
|
|
if(points.Count < 2 || currentbevelwidth == bevelwidth || bevelwidth < 0)
|
2014-12-03 23:15:26 +00:00
|
|
|
|
{
|
2016-02-17 22:23:18 +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()
|
|
|
|
|
{
|
2016-02-17 22:23:18 +00:00
|
|
|
|
if(bevelwidth > 0 || currentbevelwidth <= bevelwidth + 1)
|
2014-12-03 23:15:26 +00:00
|
|
|
|
{
|
2016-02-17 22:23:18 +00:00
|
|
|
|
bevelwidth = Math.Max(bevelwidth - General.Map.Grid.GridSize, panel.MinSpikiness);
|
|
|
|
|
panel.Spikiness = bevelwidth;
|
2014-01-16 09:32:05 +00:00
|
|
|
|
Update();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2016-03-14 10:25:27 +00:00
|
|
|
|
[BeginAction("rotateclockwise")]
|
|
|
|
|
private void IncreaseAngle()
|
|
|
|
|
{
|
|
|
|
|
panel.Angle = General.ClampAngle(panel.Angle + 5);
|
|
|
|
|
angle = Angle2D.DegToRad(panel.Angle);
|
|
|
|
|
Update();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[BeginAction("rotatecounterclockwise")]
|
|
|
|
|
private void DecreaseAngle()
|
|
|
|
|
{
|
|
|
|
|
panel.Angle = General.ClampAngle(panel.Angle - 5);
|
|
|
|
|
angle = Angle2D.DegToRad(panel.Angle);
|
|
|
|
|
Update();
|
|
|
|
|
}
|
|
|
|
|
|
2014-01-16 09:32:05 +00:00
|
|
|
|
#endregion
|
2013-09-11 09:47:53 +00:00
|
|
|
|
}
|
2012-06-06 13:37:19 +00:00
|
|
|
|
}
|