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
|
2020-05-21 12:20:02 +00:00
|
|
|
|
private double angle; // in radians
|
2016-03-14 10:25:27 +00:00
|
|
|
|
|
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-09-26 12:53:50 +00:00
|
|
|
|
panel.OnShowGuidelinesChanged += OnShowGuidelinesChanged;
|
2022-01-16 19:42:45 +00:00
|
|
|
|
panel.OnRadialDrawingChanged += OnRadialDrawingChanged;
|
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);
|
2016-09-26 12:53:50 +00:00
|
|
|
|
panel.ShowGuidelines = General.Settings.ReadPluginSetting("drawellipsemode.showguidelines", false);
|
2022-01-16 19:42:45 +00:00
|
|
|
|
panel.RadialDrawing = General.Settings.ReadPluginSetting("drawellipsemode.radialdrawing", 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);
|
2016-09-26 12:53:50 +00:00
|
|
|
|
General.Settings.WritePluginSetting("drawellipsemode.showguidelines", panel.ShowGuidelines);
|
2022-01-16 19:42:45 +00:00
|
|
|
|
General.Settings.WritePluginSetting("drawellipsemode.radialdrawing", panel.RadialDrawing);
|
|
|
|
|
|
2016-03-04 13:41:55 +00:00
|
|
|
|
|
|
|
|
|
// 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;
|
2020-05-22 20:30:32 +00:00
|
|
|
|
double hw = width / 2.0;
|
|
|
|
|
double hh = height / 2.0;
|
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);
|
2020-05-21 12:20:02 +00:00
|
|
|
|
double curAngle = angle;
|
|
|
|
|
double 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
|
|
|
|
{
|
2020-05-21 12:20:02 +00:00
|
|
|
|
double px, py;
|
2015-12-28 15:01:53 +00:00
|
|
|
|
if(doBevel)
|
2014-12-03 23:15:26 +00:00
|
|
|
|
{
|
2020-05-22 20:30:32 +00:00
|
|
|
|
px = (center.x - Math.Sin(curAngle) * (hw + currentbevelwidth));
|
|
|
|
|
py = (center.y - Math.Cos(curAngle) * (hh + currentbevelwidth));
|
2014-12-03 23:15:26 +00:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2020-05-22 20:30:32 +00:00
|
|
|
|
px = (center.x - Math.Sin(curAngle) * hw);
|
|
|
|
|
py = (center.y - Math.Cos(curAngle) * hh);
|
2013-09-11 09:47:53 +00:00
|
|
|
|
}
|
|
|
|
|
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];
|
2016-09-26 12:53:50 +00:00
|
|
|
|
|
|
|
|
|
// Now fit it inside the bounding box
|
2020-06-16 08:42:28 +00:00
|
|
|
|
double minx = double.MaxValue;
|
|
|
|
|
double miny = double.MaxValue;
|
|
|
|
|
double maxx = double.MinValue;
|
|
|
|
|
double maxy = double.MinValue;
|
2016-09-26 12:53:50 +00:00
|
|
|
|
|
|
|
|
|
// Calculate shape extents
|
|
|
|
|
foreach(Vector2D v in shape)
|
|
|
|
|
{
|
|
|
|
|
if(v.x < minx) minx = v.x;
|
|
|
|
|
if(v.x > maxx) maxx = v.x;
|
|
|
|
|
if(v.y < miny) miny = v.y;
|
|
|
|
|
if(v.y > maxy) maxy = v.y;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Calculate scalers
|
2020-05-22 20:30:32 +00:00
|
|
|
|
double scalerx = 1.0;
|
|
|
|
|
double scalery = 1.0;
|
2016-09-26 12:53:50 +00:00
|
|
|
|
|
|
|
|
|
if(minx != pStart.x || maxx != pEnd.x)
|
|
|
|
|
scalerx = (pEnd.x - pStart.x) / (maxx - minx);
|
|
|
|
|
if(miny != pStart.y)
|
|
|
|
|
scalery = (pEnd.y - pStart.y) / (maxy - miny);
|
|
|
|
|
|
|
|
|
|
// Apply scalers
|
|
|
|
|
if(scalerx != 1.0f || scalery != 1.0f)
|
|
|
|
|
{
|
|
|
|
|
for(int i = 0; i < shape.Length; i++)
|
|
|
|
|
{
|
|
|
|
|
shape[i].x = ((center.x - shape[i].x) * scalerx + center.x);
|
|
|
|
|
shape[i].y = ((center.y - shape[i].y) * scalery + center.y);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Calculate shape extents again...
|
2020-06-16 08:42:28 +00:00
|
|
|
|
minx = double.MaxValue;
|
|
|
|
|
miny = double.MaxValue;
|
2016-09-26 12:53:50 +00:00
|
|
|
|
foreach(Vector2D v in shape)
|
|
|
|
|
{
|
|
|
|
|
if(v.x < minx) minx = v.x;
|
|
|
|
|
if(v.y < miny) miny = v.y;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Calculate shape offset...
|
|
|
|
|
Vector2D offset = new Vector2D();
|
|
|
|
|
if(minx != pStart.x) offset.x = pStart.x - minx;
|
|
|
|
|
if(miny != pStart.y) offset.y = pStart.y - miny;
|
|
|
|
|
|
|
|
|
|
// Apply offset...
|
2020-05-22 20:30:32 +00:00
|
|
|
|
if(offset.x != 0.0 || offset.y != 0.0)
|
2016-09-26 12:53:50 +00:00
|
|
|
|
for(int i = 0; i < shape.Length; i++) shape[i] += offset;
|
|
|
|
|
|
|
|
|
|
// Done
|
2013-09-11 09:47:53 +00:00
|
|
|
|
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
|
|
|
|
{
|
2017-01-06 10:01:59 +00:00
|
|
|
|
bevelwidth = Math.Min(bevelwidth + General.Map.Grid.GridSize, panel.MaxSpikiness);
|
2016-02-17 22:23:18 +00:00
|
|
|
|
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
|
|
|
|
{
|
2017-01-06 10:01:59 +00:00
|
|
|
|
bevelwidth = Math.Max(bevelwidth - General.Map.Grid.GridSize, panel.MinSpikiness);
|
2016-02-17 22:23:18 +00:00
|
|
|
|
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
|
|
|
|
}
|