using CanvasDemo.Canvas;
using CanvasDemo.Data;
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace CanvasDemo.Painter
{
public class DrawPcbElement : ObjElement
{
public DrawPcbElement(DrawpcbLayer layer, ElementData data, int sideLength) : base(layer, data)
{
this.Rect.Width = sideLength;
this.Rect.Height = sideLength;
}
public override void Drawing(Graphics g)
{
g.FillRectangle(Brushes.White, Viewer.LocalToShow(Rect.X, Rect.Y, Rect.Width, 100 + 1));
PointF[] pointF;
Drawangle(Viewer.LocalToShow(Rect.X, Rect.Y, Rect.Width, 100 +1), 45, out pointF);
g.FillPolygon(Brushes.Black, pointF);
}
public void Drawangle(Rectangle rect, float angle, out PointF[] lpfs)
{
using (var graph = new GraphicsPath())
{
Point Center = new Point(rect.X + rect.Width / 2, rect.Y + rect.Height / 2);
graph.AddRectangle(rect);
var a = -angle * (Math.PI / 180);
var n1 = (float)Math.Cos(a);
var n2 = (float)Math.Sin(a);
var n3 = -(float)Math.Sin(a);
var n4 = (float)Math.Cos(a);
var n5 = (float)(Center.X * (1 - Math.Cos(a)) + Center.Y * Math.Sin(a));
var n6 = (float)(Center.Y * (1 - Math.Cos(a)) - Center.X * Math.Sin(a));
graph.Transform(new Matrix(n1, n2, n3, n4, n5, n6));
lpfs = graph.PathPoints;
}
}
public static Brush FillBrush = new SolidBrush(Color.Blue);
public static Brush ErrorBrush = new SolidBrush(Color.Red);
public override void DrawingAfter(Graphics g)
{
}
}
}