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-01-17 13:48:06 +00:00
|
|
|
|
public DrawEllipseMode() {
|
2013-09-11 09:47:53 +00:00
|
|
|
|
undoName = "Ellipse draw";
|
|
|
|
|
shapeName = "ellipse";
|
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
|
|
|
|
|
|
|
|
|
|
override protected void setupInterface() {
|
|
|
|
|
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-01-16 09:32:05 +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-01-16 09:32:05 +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
|
|
|
|
|
|
2013-09-11 09:47:53 +00:00
|
|
|
|
override protected Vector2D[] getShape(Vector2D pStart, Vector2D pEnd) {
|
|
|
|
|
//no shape
|
2014-02-28 14:32:20 +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
|
2014-02-28 14:32:20 +00:00
|
|
|
|
if (bevelWidth < 0) {
|
2014-07-02 10:12:53 +00:00
|
|
|
|
currentBevelWidth = -Math.Min(Math.Abs(bevelWidth), Math.Min(width, height) / 2) + 1;
|
2014-02-28 14:32:20 +00:00
|
|
|
|
} else {
|
|
|
|
|
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;
|
|
|
|
|
int px, py;
|
2012-06-06 13:37:19 +00:00
|
|
|
|
|
2013-09-11 09:47:53 +00:00
|
|
|
|
for (int i = 0; i < subdivisions; i++) {
|
|
|
|
|
if (doBevel) {
|
|
|
|
|
px = (int)(center.x - (float)Math.Sin(curAngle) * (hw + currentBevelWidth));
|
|
|
|
|
py = (int)(center.y - (float)Math.Cos(curAngle) * (hh + currentBevelWidth));
|
|
|
|
|
} else {
|
|
|
|
|
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
|
|
|
|
|
2013-09-11 09:47:53 +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
|
|
|
|
|
|
|
|
|
|
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-02-10 09:26:13 +00:00
|
|
|
|
public override void OnHelp() {
|
|
|
|
|
General.ShowHelp("/gzdb/features/classic_modes/mode_drawellipse.html");
|
|
|
|
|
}
|
|
|
|
|
|
2014-01-16 09:32:05 +00:00
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
#region ================== Actions
|
|
|
|
|
|
2013-09-11 09:47:53 +00:00
|
|
|
|
override protected void increaseSubdivLevel() {
|
2014-02-28 14:32:20 +00:00
|
|
|
|
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
|
|
|
|
|
2013-09-11 09:47:53 +00:00
|
|
|
|
override protected void decreaseSubdivLevel() {
|
2014-02-28 14:32:20 +00:00
|
|
|
|
if (subdivisions - minSubdivisions > 1) {
|
2013-09-11 09:47:53 +00:00
|
|
|
|
subdivisions -= 2;
|
2014-01-16 09:32:05 +00:00
|
|
|
|
panel.Subdivisions = subdivisions;
|
|
|
|
|
Update();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
|
|
protected override void decreaseBevel() {
|
2014-07-02 10:12:53 +00:00
|
|
|
|
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
|
|
|
|
}
|