2014-01-16 09:32:05 +00:00
|
|
|
|
#region ================== Namespaces
|
|
|
|
|
|
|
|
|
|
using System;
|
|
|
|
|
using CodeImp.DoomBuilder.Controls;
|
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 Docker settingsdocker;
|
|
|
|
|
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;
|
|
|
|
|
panel.OnValueChanged += OptionsPanelOnValueChanged;
|
|
|
|
|
settingsdocker = new Docker("drawrectangle", "Draw Ellipse", panel);
|
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() {
|
|
|
|
|
General.Interface.AddDocker(settingsdocker);
|
|
|
|
|
General.Interface.SelectDocker(settingsdocker);
|
|
|
|
|
bevelWidth = panel.Aquity;
|
|
|
|
|
subdivisions = panel.Subdivisions;
|
2013-03-18 13:52:27 +00:00
|
|
|
|
}
|
|
|
|
|
|
2014-01-16 09:32:05 +00:00
|
|
|
|
override protected void removeInterface() {
|
|
|
|
|
General.Interface.RemoveDocker(settingsdocker);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
#region ================== Methods
|
|
|
|
|
|
2013-09-11 09:47:53 +00:00
|
|
|
|
override protected Vector2D[] getShape(Vector2D pStart, Vector2D pEnd) {
|
|
|
|
|
//no shape
|
|
|
|
|
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
|
|
|
|
|
if(pEnd.x == pStart.x || pEnd.y == pStart.y)
|
2014-01-16 09:32:05 +00:00
|
|
|
|
return new[] { pStart, pEnd };
|
2013-03-18 13:52:27 +00:00
|
|
|
|
|
2013-09-11 09:47:53 +00:00
|
|
|
|
//got shape
|
|
|
|
|
int bevelSign = (bevelWidth > 0 ? 1 : -1);
|
|
|
|
|
currentBevelWidth = Math.Min(Math.Abs(bevelWidth), Math.Min(width, height) / 2) * bevelSign;
|
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() {
|
|
|
|
|
return "BVL: "+bevelWidth+"; VERTS: "+subdivisions;
|
|
|
|
|
}
|
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) {
|
|
|
|
|
bevelWidth = panel.Aquity;
|
|
|
|
|
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() {
|
|
|
|
|
if (subdivisions < maxSubdivisions) {
|
|
|
|
|
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() {
|
|
|
|
|
if (subdivisions > minSubdivisions) {
|
|
|
|
|
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) {
|
|
|
|
|
bevelWidth += General.Map.Grid.GridSize;
|
|
|
|
|
panel.Aquity = bevelWidth;
|
2013-09-11 09:47:53 +00:00
|
|
|
|
Update();
|
|
|
|
|
}
|
|
|
|
|
}
|
2014-01-16 09:32:05 +00:00
|
|
|
|
|
|
|
|
|
protected override void decreaseBevel() {
|
|
|
|
|
if(currentBevelWidth == bevelWidth || bevelWidth > 0) {
|
|
|
|
|
bevelWidth -= General.Map.Grid.GridSize;
|
|
|
|
|
panel.Aquity = bevelWidth;
|
|
|
|
|
Update();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#endregion
|
2013-09-11 09:47:53 +00:00
|
|
|
|
}
|
2012-06-06 13:37:19 +00:00
|
|
|
|
}
|