2012-06-06 13:37:19 +00:00
|
|
|
|
using System;
|
|
|
|
|
using CodeImp.DoomBuilder.Editing;
|
|
|
|
|
using CodeImp.DoomBuilder.Geometry;
|
|
|
|
|
|
|
|
|
|
namespace CodeImp.DoomBuilder.BuilderModes.ClassicModes {
|
|
|
|
|
[EditMode(DisplayName = "Draw Ellipse Mode",
|
|
|
|
|
SwitchAction = "drawellipsemode",
|
|
|
|
|
AllowCopyPaste = false,
|
|
|
|
|
Volatile = true,
|
|
|
|
|
Optional = false)]
|
|
|
|
|
|
|
|
|
|
public class DrawEllipseMode : DrawRectangleMode {
|
2013-03-18 13:52:27 +00:00
|
|
|
|
private static int storedSubdivisions;
|
|
|
|
|
|
2012-06-06 13:37:19 +00:00
|
|
|
|
public DrawEllipseMode() : base() {
|
|
|
|
|
maxSubdivisions = 32;
|
|
|
|
|
minSubdivisions = 6;
|
|
|
|
|
undoName = "Ellipse draw";
|
|
|
|
|
shapeName = "ellipse";
|
|
|
|
|
|
2013-03-18 13:52:27 +00:00
|
|
|
|
if(storedSubdivisions == 0)
|
|
|
|
|
storedSubdivisions = minSubdivisions + 2;
|
|
|
|
|
subdivisions = storedSubdivisions;
|
2012-06-06 13:37:19 +00:00
|
|
|
|
}
|
|
|
|
|
|
2013-03-18 13:52:27 +00:00
|
|
|
|
public override void OnDisengage() {
|
|
|
|
|
base.OnDisengage();
|
|
|
|
|
storedSubdivisions = subdivisions;
|
|
|
|
|
}
|
|
|
|
|
|
2012-06-06 13:37:19 +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];
|
|
|
|
|
|
2013-03-18 13:52:27 +00:00
|
|
|
|
//line
|
|
|
|
|
if(pEnd.x == pStart.x || pEnd.y == pStart.y)
|
|
|
|
|
return new Vector2D[] { pStart, pEnd };
|
|
|
|
|
|
2012-06-06 13:37:19 +00:00
|
|
|
|
//got shape
|
|
|
|
|
int bevelSign = (bevelWidth > 0 ? 1 : -1);
|
2012-06-07 01:06:37 +00:00
|
|
|
|
currentBevelWidth = Math.Min(Math.Abs(bevelWidth), Math.Min(width, height) / 2) * bevelSign;
|
2012-06-06 13:37:19 +00:00
|
|
|
|
|
|
|
|
|
Vector2D[] shape = new Vector2D[subdivisions + 1];
|
|
|
|
|
|
|
|
|
|
bool doBevel = false;
|
|
|
|
|
int hw = width / 2;
|
|
|
|
|
int hh = height / 2;
|
|
|
|
|
|
|
|
|
|
Vector2D center = new Vector2D(pStart.x + hw, pStart.y + hh);
|
|
|
|
|
float curAngle = 0;
|
2013-04-11 09:27:16 +00:00
|
|
|
|
float angleStep = -Angle2D.PI / subdivisions * 2;
|
2012-06-06 13:37:19 +00:00
|
|
|
|
int px, py;
|
|
|
|
|
|
|
|
|
|
for (int i = 0; i < subdivisions; i++) {
|
|
|
|
|
if (doBevel) {
|
2012-06-07 01:06:37 +00:00
|
|
|
|
px = (int)(center.x - (float)Math.Sin(curAngle) * (hw + currentBevelWidth));
|
|
|
|
|
py = (int)(center.y - (float)Math.Cos(curAngle) * (hh + currentBevelWidth));
|
2012-06-06 13:37:19 +00:00
|
|
|
|
} 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-07 01:06:37 +00:00
|
|
|
|
protected override string getHintText() {
|
|
|
|
|
return "BVL: "+bevelWidth+"; VERTS: "+subdivisions;
|
|
|
|
|
}
|
|
|
|
|
|
2012-06-06 13:37:19 +00:00
|
|
|
|
//ACTIONS
|
|
|
|
|
override protected void increaseSubdivLevel() {
|
|
|
|
|
if (subdivisions < maxSubdivisions) {
|
|
|
|
|
subdivisions += 2;
|
|
|
|
|
Update();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
override protected void decreaseSubdivLevel() {
|
|
|
|
|
if (subdivisions > minSubdivisions) {
|
|
|
|
|
subdivisions -= 2;
|
|
|
|
|
Update();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|