private void pnlSampleRoomShape_Paint(object sender, PaintEventArgs e) { var graph = pnlSampleRoomShape.CreateGraphics(); var path = new GraphicsPath(); var pen = new Pen(Color.Black, 2.0f); var rect = new RectangleF(10, 10, 3 * Settings.GridSize, 2 * Settings.GridSize); if (cboDrawType.SelectedItem == itemRoundedCorners) { var corners = new CornerRadii() { BottomLeft = txtBottomLeft.Value, BottomRight = txtBottomRight.Value, TopRight = txtTopRight.Value, TopLeft = txtTopLeft.Value }; path.AddArc(rect.X + rect.Width - ((float)corners.TopRight * 2), rect.Y, (float)corners.TopRight * 2, (float)corners.TopRight * 2, 270, 90); path.AddArc(rect.X + rect.Width - ((float)corners.BottomRight * 2), rect.Y + rect.Height - ((float)corners.BottomRight * 2), (float)corners.BottomRight * 2, (float)corners.BottomRight * 2, 0, 90); path.AddArc(rect.X, rect.Y + rect.Height - ((float)corners.BottomLeft * 2), (float)corners.BottomLeft * 2, (float)corners.BottomLeft * 2, 90, 90); path.AddArc(rect.X, rect.Y, (float)corners.TopLeft * 2, (float)corners.TopLeft * 2, 180, 90); path.CloseFigure(); } else if (cboDrawType.SelectedItem == itemEllipse) { path.AddEllipse(new RectangleF(rect.X, rect.Y, rect.Width, rect.Height)); } graph.DrawPath(pen, path); }
public override object CreateInstance(ITypeDescriptorContext context, IDictionary propertyValues) { if (context == null) { throw new ArgumentNullException("context"); } if (propertyValues == null) { throw new ArgumentNullException("propertyValues"); } CornerRadii value = (CornerRadii)context.PropertyDescriptor.GetValue(context.Instance); int item = (int)propertyValues["All"]; if (value.All != item) { return(new CornerRadii(item)); } return(new CornerRadii((int)propertyValues["TopLeft"], (int)propertyValues["TopRight"], (int)propertyValues["BottomLeft"], (int)propertyValues["BottomRight"])); }
public override object ConvertTo(ITypeDescriptorContext context, CultureInfo culture, object value, Type destinationType) { if (destinationType == null) { throw new ArgumentNullException("destinationType"); } if (value is CornerRadii) { if (destinationType == typeof(string)) { CornerRadii cornerRadii = (CornerRadii)value; if (culture == null) { culture = CultureInfo.CurrentCulture; } string str = string.Concat(culture.TextInfo.ListSeparator, " "); TypeConverter converter = TypeDescriptor.GetConverter(typeof(int)); string[] strArrays = new string[4]; strArrays[0] = converter.ConvertToString(context, culture, cornerRadii.TopLeft); strArrays[1] = converter.ConvertToString(context, culture, cornerRadii.TopRight); strArrays[2] = converter.ConvertToString(context, culture, cornerRadii.BottomLeft); strArrays[3] = converter.ConvertToString(context, culture, cornerRadii.BottomRight); return(string.Join(str, strArrays)); } } if (destinationType == typeof(InstanceDescriptor)) { CornerRadii cornerRadii1 = (CornerRadii)value; if (cornerRadii1.ShouldSerializeAll()) { ConstructorInfo constructor = typeof(CornerRadii).GetConstructor(new Type[] { typeof(int) }); object[] all = new object[] { cornerRadii1.All }; return(new InstanceDescriptor(constructor, all)); } Type type = typeof(CornerRadii); Type[] typeArray = new Type[] { typeof(int), typeof(int), typeof(int), typeof(int) }; ConstructorInfo constructorInfo = type.GetConstructor(typeArray); object[] left = new object[] { cornerRadii1.TopLeft, cornerRadii1.TopRight, cornerRadii1.BottomLeft, cornerRadii1.BottomRight }; return(new InstanceDescriptor(constructorInfo, left)); } return(base.ConvertTo(context, culture, value, destinationType)); }
public Vector GetCorner(CompassPoint point, RoomShape myRmShape = RoomShape.SquareCorners, CornerRadii corners = null) { bool isOctagonal = (myRmShape == RoomShape.Octagonal); bool isRounded = (myRmShape == RoomShape.RoundedCorners); bool isEllipse = (myRmShape == RoomShape.Ellipse); double angleInRadians; if (myRmShape == RoomShape.Ellipse) { angleInRadians = CompassPointHelper.CalcRadianForEllipse(point, this); return(new Vector(Center.X + (float)((Width / 2.0) * Math.Cos(angleInRadians)), Center.Y + (float)((Height / 2.0) * Math.Sin(angleInRadians)))); } if (myRmShape == RoomShape.Ellipse) { if (point == CompassPoint.NorthEast || point == CompassPoint.NorthWest || point == CompassPoint.SouthWest || point == CompassPoint.SouthEast) { angleInRadians = CompassPointHelper.CalcRadianForEllipse(point, this); if (point == CompassPoint.NorthEast) { var rect = new Rect(X + Width, Y, (float)corners.TopRight, (float)corners.TopRight); return(new Vector((rect.Center.X - (float)(corners.TopRight / 2.0)) - (float)((corners.TopRight / 2.0) * Math.Cos(angleInRadians)), (rect.Center.Y + (float)(corners.TopLeft / 4.0)) + (float)((corners.TopRight / 2.0) * Math.Sin(angleInRadians)))); } if (point == CompassPoint.NorthWest) { var rect = new Rect(X, Y, (float)corners.TopLeft, (float)corners.TopLeft); return(new Vector((rect.Center.X - (float)(corners.TopLeft / 2.0)) - (float)((corners.TopLeft / 2.0) * Math.Cos(angleInRadians)), (rect.Center.Y + (float)(corners.TopLeft / 4.0)) + (float)((corners.TopLeft / 2.0) * Math.Sin(angleInRadians)))); } if (point == CompassPoint.SouthWest) { var rect = new Rect(X, Y + Height, (float)corners.BottomLeft, (float)corners.BottomLeft); return(new Vector((rect.Center.X - (float)(corners.BottomLeft / 2.0)) - (float)((corners.BottomLeft / 2.0) * Math.Cos(angleInRadians)), (rect.Center.Y - (float)(corners.BottomLeft / 2.0)) - (float)((corners.BottomLeft / 2.0) * Math.Sin(angleInRadians)))); } if (point == CompassPoint.SouthEast) { var rect = new Rect(X + Width, Y + Height, (float)corners.BottomRight, (float)corners.BottomRight); return(new Vector((rect.Center.X - (float)(corners.BottomRight / 2.0)) - (float)((corners.BottomRight / 2.0) * Math.Cos(angleInRadians)), (rect.Center.Y - (float)(corners.BottomRight / 2.0)) - (float)((corners.BottomRight / 2.0) * Math.Sin(angleInRadians)))); } } } switch (point) { case CompassPoint.North: return(new Vector(X + Width / 2, Y)); case CompassPoint.NorthNorthEast: return(new Vector(X + Width * 3 / 4, Y)); case CompassPoint.NorthEast: if (isOctagonal) { return(new Vector(X + Width * 7 / 8, Y + Height * 1 / 8)); } if (isRounded) { return(new Vector((float)(X + Width - 0.25 * corners.TopLeft), (float)(Y + 0.25 * corners.TopLeft))); } return(new Vector(X + Width, Y)); case CompassPoint.EastNorthEast: return(new Vector(X + Width, Y + Height / 4)); case CompassPoint.East: return(new Vector(X + Width, Y + Height / 2)); case CompassPoint.EastSouthEast: return(new Vector(X + Width, Y + Height * 3 / 4)); case CompassPoint.SouthEast: if (isOctagonal) { return(new Vector(X + Width * 7 / 8, Y + Height * 7 / 8)); } if (isRounded) { return(new Vector((float)(X + Width - 0.25 * corners.TopLeft), (float)(Y + Height - 0.25 * corners.TopLeft))); } return(new Vector(X + Width, Y + Height)); case CompassPoint.SouthSouthEast: return(new Vector(X + Width * 3 / 4, Y + Height)); case CompassPoint.South: return(new Vector(X + Width / 2, Y + Height)); case CompassPoint.SouthSouthWest: return(new Vector(X + Width / 4, Y + Height)); case CompassPoint.SouthWest: if (isOctagonal) { return(new Vector(X + Width * 1 / 8, Y + Height * 7 / 8)); } if (isRounded) { return(new Vector((float)(X + 0.3 * corners.TopLeft), (float)(Y + Height - 0.3 * corners.TopLeft))); } return(new Vector(X, Y + Height)); case CompassPoint.WestSouthWest: return(new Vector(X, Y + Height * 3 / 4)); case CompassPoint.West: return(new Vector(X, Y + Height / 2)); case CompassPoint.WestNorthWest: return(new Vector(X, Y + Height / 4)); case CompassPoint.NorthWest: if (isOctagonal) { return(new Vector(X + Width * 1 / 8, Y + Height * 1 / 8)); } if (isRounded) { return(new Vector((float)(X + 0.3 * corners.TopLeft), (float)(Y + 0.3 * corners.TopLeft))); } return(new Vector(X, Y)); case CompassPoint.NorthNorthWest: return(new Vector(X + Width / 4, Y)); default: throw new InvalidOperationException(); } }
static CornerRadii() { CornerRadii.Empty = new CornerRadii(0); }
public Vector GetCorner(CompassPoint point, bool ellipse = false, CornerRadii corners = null) { if (ellipse) { return(new Vector(Center.X + (float)((Width / 2.0) * Math.Cos(CompassPointHelper.GetAngleInRadians(point))), Center.Y + (float)((Height / 2.0) * Math.Sin(CompassPointHelper.GetAngleInRadians(point))))); } if (corners != null) { if (point != CompassPoint.East && point != CompassPoint.West && point != CompassPoint.North && point != CompassPoint.South) { if (corners.TopRight > 10.0 && (point == CompassPoint.EastNorthEast || point == CompassPoint.NorthEast || point == CompassPoint.NorthNorthEast)) { return(new Vector(Center.X + (float)((Width / 2.0) * Math.Cos(CompassPointHelper.GetAngleInRadians(point))), Center.Y + (float)((Height / 2.0) * Math.Sin(CompassPointHelper.GetAngleInRadians(point))))); } if (corners.TopLeft > 10.0 && (point == CompassPoint.WestNorthWest || point == CompassPoint.NorthWest || point == CompassPoint.NorthNorthWest)) { return(new Vector(Center.X + (float)((Width / 2.0) * Math.Cos(CompassPointHelper.GetAngleInRadians(point))), Center.Y + (float)((Height / 2.0) * Math.Sin(CompassPointHelper.GetAngleInRadians(point))))); } if (corners.BottomLeft > 10.0 && (point == CompassPoint.WestSouthWest || point == CompassPoint.SouthWest || point == CompassPoint.SouthSouthWest)) { return(new Vector(Center.X + (float)((Width / 2.0) * Math.Cos(CompassPointHelper.GetAngleInRadians(point))), Center.Y + (float)((Height / 2.0) * Math.Sin(CompassPointHelper.GetAngleInRadians(point))))); } if (corners.BottomRight > 10.0 && (point == CompassPoint.SouthSouthEast || point == CompassPoint.SouthEast || point == CompassPoint.EastSouthEast)) { return(new Vector(Center.X + (float)((Width / 2.0) * Math.Cos(CompassPointHelper.GetAngleInRadians(point))), Center.Y + (float)((Height / 2.0) * Math.Sin(CompassPointHelper.GetAngleInRadians(point))))); } } } switch (point) { case CompassPoint.North: return(new Vector(X + Width / 2, Y)); case CompassPoint.NorthNorthEast: return(new Vector(X + Width * 3 / 4, Y)); case CompassPoint.NorthEast: return(new Vector(X + Width, Y)); case CompassPoint.EastNorthEast: return(new Vector(X + Width, Y + Height / 4)); case CompassPoint.East: return(new Vector(X + Width, Y + Height / 2)); case CompassPoint.EastSouthEast: return(new Vector(X + Width, Y + Height * 3 / 4)); case CompassPoint.SouthEast: return(new Vector(X + Width, Y + Height)); case CompassPoint.SouthSouthEast: return(new Vector(X + Width * 3 / 4, Y + Height)); case CompassPoint.South: return(new Vector(X + Width / 2, Y + Height)); case CompassPoint.SouthSouthWest: return(new Vector(X + Width / 4, Y + Height)); case CompassPoint.SouthWest: return(new Vector(X, Y + Height)); case CompassPoint.WestSouthWest: return(new Vector(X, Y + Height * 3 / 4)); case CompassPoint.West: return(new Vector(X, Y + Height / 2)); case CompassPoint.WestNorthWest: return(new Vector(X, Y + Height / 4)); case CompassPoint.NorthWest: return(new Vector(X, Y)); case CompassPoint.NorthNorthWest: return(new Vector(X + Width / 4, Y)); default: throw new InvalidOperationException(); } }
private void pnlSampleRoomShape_Paint(object sender, PaintEventArgs e) { var graph = pnlSampleRoomShape.CreateGraphics(); var path = new GraphicsPath(); var pen = new Pen(Color.Black,2.0f); var rect = new RectangleF(10,10, 3 * Settings.GridSize, 2 * Settings.GridSize); if (cboDrawType.SelectedItem == itemRoundedCorners) { var corners = new CornerRadii() { BottomLeft = txtBottomLeft.Value, BottomRight = txtBottomRight.Value, TopRight = txtTopRight.Value, TopLeft = txtTopLeft.Value }; path.AddArc(rect.X + rect.Width - ((float)corners.TopRight * 2), rect.Y, (float)corners.TopRight * 2, (float)corners.TopRight * 2, 270, 90); path.AddArc(rect.X + rect.Width - ((float)corners.BottomRight * 2), rect.Y + rect.Height - ((float)corners.BottomRight * 2), (float)corners.BottomRight * 2, (float)corners.BottomRight * 2, 0, 90); path.AddArc(rect.X, rect.Y + rect.Height - ((float)corners.BottomLeft * 2), (float)corners.BottomLeft * 2, (float)corners.BottomLeft * 2, 90, 90); path.AddArc(rect.X, rect.Y, (float)corners.TopLeft * 2, (float)corners.TopLeft * 2, 180, 90); path.CloseFigure(); } else if (cboDrawType.SelectedItem == itemEllipse) { path.AddEllipse(new RectangleF(rect.X, rect.Y, rect.Width, rect.Height)); } graph.DrawPath(pen,path); }
public Vector GetCorner(CompassPoint point, RoomShape myRmShape = RoomShape.SquareCorners, CornerRadii corners = null) { bool isOctagonal = (myRmShape == RoomShape.Octagonal); bool isRounded = (myRmShape == RoomShape.RoundedCorners); bool isEllipse = (myRmShape == RoomShape.Ellipse); double angleInRadians; if (myRmShape == RoomShape.Ellipse) { angleInRadians = CompassPointHelper.CalcRadianForEllipse(point, this); return new Vector(Center.X + (float)((Width/2.0) * Math.Cos(angleInRadians)), Center.Y + (float)((Height / 2.0) * Math.Sin(angleInRadians))); } if (myRmShape == RoomShape.Ellipse) { if (point == CompassPoint.NorthEast || point == CompassPoint.NorthWest || point == CompassPoint.SouthWest || point == CompassPoint.SouthEast) { angleInRadians = CompassPointHelper.CalcRadianForEllipse(point, this); if (point == CompassPoint.NorthEast) { var rect = new Rect(X + Width, Y , (float) corners.TopRight, (float) corners.TopRight); return new Vector((rect.Center.X - (float) (corners.TopRight/2.0)) - (float) ((corners.TopRight/2.0)*Math.Cos(angleInRadians)), (rect.Center.Y + (float)(corners.TopLeft / 4.0)) + (float) ((corners.TopRight/2.0)*Math.Sin(angleInRadians))); } if (point == CompassPoint.NorthWest) { var rect = new Rect(X, Y, (float) corners.TopLeft, (float) corners.TopLeft); return new Vector((rect.Center.X - (float) (corners.TopLeft/2.0)) - (float) ((corners.TopLeft/2.0)*Math.Cos(angleInRadians)), (rect.Center.Y + (float)(corners.TopLeft / 4.0)) + (float) ((corners.TopLeft/2.0)*Math.Sin(angleInRadians))); } if (point == CompassPoint.SouthWest) { var rect = new Rect(X, Y + Height, (float) corners.BottomLeft, (float) corners.BottomLeft); return new Vector((rect.Center.X - (float)(corners.BottomLeft / 2.0)) - (float)((corners.BottomLeft/2.0)*Math.Cos(angleInRadians)), (rect.Center.Y - (float)(corners.BottomLeft / 2.0)) - (float) ((corners.BottomLeft/2.0)*Math.Sin(angleInRadians))); } if (point == CompassPoint.SouthEast) { var rect = new Rect(X + Width, Y + Height, (float) corners.BottomRight, (float) corners.BottomRight); return new Vector((rect.Center.X - (float)(corners.BottomRight/2.0)) - (float) ((corners.BottomRight/2.0)*Math.Cos(angleInRadians)), (rect.Center.Y - (float)(corners.BottomRight/2.0 )) - (float) ((corners.BottomRight/2.0)*Math.Sin(angleInRadians))); } } } switch (point) { case CompassPoint.North: return new Vector(X + Width/2, Y); case CompassPoint.NorthNorthEast: return new Vector(X + Width*3/4, Y); case CompassPoint.NorthEast: if (isOctagonal) return new Vector (X + Width * 7/8, Y + Height * 1/8); if (isRounded) return new Vector((float)(X + Width - 0.25 * corners.TopLeft), (float)(Y + 0.25 * corners.TopLeft)); return new Vector(X + Width, Y); case CompassPoint.EastNorthEast: return new Vector(X + Width, Y + Height/4); case CompassPoint.East: return new Vector(X + Width, Y + Height/2); case CompassPoint.EastSouthEast: return new Vector(X + Width, Y + Height*3/4); case CompassPoint.SouthEast: if (isOctagonal) return new Vector (X + Width * 7/8, Y + Height * 7/8); if (isRounded) return new Vector((float)(X + Width - 0.25 * corners.TopLeft), (float)(Y + Height - 0.25 * corners.TopLeft)); return new Vector(X + Width, Y + Height); case CompassPoint.SouthSouthEast: return new Vector(X + Width*3/4, Y + Height); case CompassPoint.South: return new Vector(X + Width/2, Y + Height); case CompassPoint.SouthSouthWest: return new Vector(X + Width/4, Y + Height); case CompassPoint.SouthWest: if (isOctagonal) return new Vector (X + Width * 1/8, Y + Height * 7/8); if (isRounded) return new Vector((float)(X + 0.3 * corners.TopLeft), (float)(Y + Height - 0.3 * corners.TopLeft)); return new Vector(X, Y + Height); case CompassPoint.WestSouthWest: return new Vector(X, Y + Height*3/4); case CompassPoint.West: return new Vector(X, Y + Height/2); case CompassPoint.WestNorthWest: return new Vector(X, Y + Height/4); case CompassPoint.NorthWest: if (isOctagonal) return new Vector (X + Width * 1/8, Y + Height * 1/8); if (isRounded) return new Vector((float)(X + 0.3 * corners.TopLeft), (float)(Y + 0.3 * corners.TopLeft)); return new Vector(X, Y); case CompassPoint.NorthNorthWest: return new Vector(X + Width/4, Y); default: throw new InvalidOperationException(); } }
public Vector GetCorner(CompassPoint point, bool ellipse = false, CornerRadii corners = null) { if (ellipse) { return new Vector(Center.X + (float)((Width/2.0) * Math.Cos(CompassPointHelper.GetAngleInRadians(point))), Center.Y + (float)((Height / 2.0) * Math.Sin(CompassPointHelper.GetAngleInRadians(point)))); } if (corners != null) { if (point != CompassPoint.East && point != CompassPoint.West && point != CompassPoint.North && point != CompassPoint.South) { if (corners.TopRight > 10.0 && (point == CompassPoint.EastNorthEast || point == CompassPoint.NorthEast || point == CompassPoint.NorthNorthEast)) return new Vector(Center.X + (float) ((Width/2.0)*Math.Cos(CompassPointHelper.GetAngleInRadians(point))), Center.Y + (float) ((Height/2.0)*Math.Sin(CompassPointHelper.GetAngleInRadians(point)))); if (corners.TopLeft > 10.0 && (point == CompassPoint.WestNorthWest || point == CompassPoint.NorthWest || point == CompassPoint.NorthNorthWest)) return new Vector(Center.X + (float)((Width / 2.0) * Math.Cos(CompassPointHelper.GetAngleInRadians(point))), Center.Y + (float)((Height / 2.0) * Math.Sin(CompassPointHelper.GetAngleInRadians(point)))); if (corners.BottomLeft > 10.0 && (point == CompassPoint.WestSouthWest || point == CompassPoint.SouthWest || point == CompassPoint.SouthSouthWest)) return new Vector(Center.X + (float)((Width / 2.0) * Math.Cos(CompassPointHelper.GetAngleInRadians(point))), Center.Y + (float)((Height / 2.0) * Math.Sin(CompassPointHelper.GetAngleInRadians(point)))); if (corners.BottomRight > 10.0 && (point == CompassPoint.SouthSouthEast || point == CompassPoint.SouthEast || point == CompassPoint.EastSouthEast)) return new Vector(Center.X + (float)((Width / 2.0) * Math.Cos(CompassPointHelper.GetAngleInRadians(point))), Center.Y + (float)((Height / 2.0) * Math.Sin(CompassPointHelper.GetAngleInRadians(point)))); } } switch (point) { case CompassPoint.North: return new Vector(X + Width/2, Y); case CompassPoint.NorthNorthEast: return new Vector(X + Width*3/4, Y); case CompassPoint.NorthEast: return new Vector(X + Width, Y); case CompassPoint.EastNorthEast: return new Vector(X + Width, Y + Height/4); case CompassPoint.East: return new Vector(X + Width, Y + Height/2); case CompassPoint.EastSouthEast: return new Vector(X + Width, Y + Height*3/4); case CompassPoint.SouthEast: return new Vector(X + Width, Y + Height); case CompassPoint.SouthSouthEast: return new Vector(X + Width*3/4, Y + Height); case CompassPoint.South: return new Vector(X + Width/2, Y + Height); case CompassPoint.SouthSouthWest: return new Vector(X + Width/4, Y + Height); case CompassPoint.SouthWest: return new Vector(X, Y + Height); case CompassPoint.WestSouthWest: return new Vector(X, Y + Height*3/4); case CompassPoint.West: return new Vector(X, Y + Height/2); case CompassPoint.WestNorthWest: return new Vector(X, Y + Height/4); case CompassPoint.NorthWest: return new Vector(X, Y); case CompassPoint.NorthNorthWest: return new Vector(X + Width/4, Y); default: throw new InvalidOperationException(); } }