public static CodePos <TCX, TCY> From(TCX cx, TCY cy) { return(new CodePos <TCX, TCY> { X = CodeX <TCX> .From(cx), Y = CodeY <TCY> .From(cy), }); }
public LayoutPos GetLayoutPos(Angle A) { var lw = TargetProcess.PositionerX(CodeX <Distance> .From(TargetProcess.Width / 2 + Width / 2), CodeY <Distance> .From(TargetProcess.Height / 2 + Height / 2)); var lh = TargetProcess.PositionerY(CodeX <Distance> .From(TargetProcess.Width / 2 + Width / 2), CodeY <Distance> .From(TargetProcess.Height / 2 + Height / 2)); var lpos = TargetProcess.GetLayoutPos(); // Parts Location var lois = GeoEu.GetLocationOfInscribedSquareInCircle(A); // Connector Location Unit (0.7 times) return(LayoutPos.From( lpos.X // Parts Location + lw * MathUtil.Root2 // R (Circle of the four vertices) * lois.X, // Location of inscribed square in circle lpos.Y // Parts Location + lh * MathUtil.Root2 // R (Circle of the four vertices) * lois.Y // Location of inscribed square in circle )); }
/// <summary> /// Visualize /// </summary> /// <param name="dp"></param> public override void Draw(DrawProperty dp) { // Connector grip size var lcsz = LayoutSize.From(PositionerX(CodeX <Distance> .From(Width), null), PositionerY(null, CodeY <Distance> .From(Height))); var scsz = ScreenSize.From(dp.Pane, lcsz); // Process Size var spsz0 = ScreenSize.From(dp.Pane, LayoutSize.From(PositionerX(CodeX <Distance> .From(ProcessFrom.Width), null), PositionerY(null, CodeY <Distance> .From(ProcessFrom.Height)))); var spsz1 = ScreenSize.From(dp.Pane, LayoutSize.From(PositionerX(CodeX <Distance> .From(ProcessTo.Width), null), PositionerY(null, CodeY <Distance> .From(ProcessTo.Height)))); var sc0 = ProcessFrom.GetScreenPos(dp.Pane); var sc1 = ProcessTo.GetScreenPos(dp.Pane); _angle0 = GeoEu.Angle(sc0.X.Sx, sc0.Y.Sy, sc1.X.Sx, sc1.Y.Sy); var k0 = GeoEu.GetLocationOfInscribedSquareInCircle(_angle0); var sr0 = ScreenRect.FromCS(ScreenPos.From(sc0.X + k0.X * (spsz0.Width + scsz.Width) / MathUtil.Root2, sc0.Y + -k0.Y * (spsz0.Height + scsz.Height) / MathUtil.Root2), scsz); var a1 = GeoEu.Angle(sc1.X.Sx, sc1.Y.Sy, sc0.X.Sx, sc0.Y.Sy); var k1 = GeoEu.GetLocationOfInscribedSquareInCircle(a1); var sr1 = ScreenRect.FromCS(ScreenPos.From(sc1.X + k1.X * (spsz1.Width + scsz.Width) / MathUtil.Root2, sc1.Y + -k1.Y * (spsz1.Height + scsz.Height) / MathUtil.Root2), scsz); _p0 = sr0.C + ScreenPos.From(k0.X * sr0.Width / MathUtil.Root2, -k0.Y * sr0.Height / MathUtil.Root2); _p1 = sr1.C; // from: on the grip edge switch (State) { case States.SELECTING: dp.Graphics.DrawLine(_(_p0), _(_p1), Colors.Red); break; case States.HOVER: dp.Graphics.DrawLine(_(_p0), _(_p1), Colors.Cyan); break; default: dp.Graphics.DrawLine(_(_p0), _(_p1), Colors.White); break; } dp.Graphics.DrawRectangle(_(sr0), Colors.White); dp.Graphics.FillRectangle(_(sr1), Colors.White); }
/// <summary> /// Drawing main /// </summary> /// <param name="dp"></param> public override void Draw(DrawProperty dp) { var lpos = GetLayoutPos(); var sc = ScreenPos.From(dp.Pane, lpos); var lsiz = LayoutSize.From(PositionerX(CodeX <Distance> .From(Width), null), PositionerY(null, CodeY <Distance> .From(Height))); var ssiz = ScreenSize.From(dp.Pane, lsiz); var sr = ScreenRect.FromCWH(sc, ssiz.Width, ssiz.Height); if (IsSelected) { // draw the requested position indicator (on the inscribed square in the circle) var A = GetAngle(lpos); var lposIn = GetLayoutPos(A); var scIn = ScreenPos.From(dp.Pane, lposIn); var srIn = ScreenRect.FromCWH(scIn, ssiz.Width, ssiz.Height); dp.Graphics.DrawLine(_(scIn), _(sc), ConnectingColor); if (Design == Designs.IN) { dp.Graphics.FillRectangle(_(srIn), Colors.DarkGray); } else { dp.Graphics.DrawRectangle(_(srIn), Colors.DarkGray); } // draw selected color dp.Graphics.DrawRectangle(_(sr), SelectingColor, 4f); dp.Graphics.FillRectangle(_(sr), SelectingColor); } if (Design == Designs.IN) { dp.Graphics.FillRectangle(_(sr), GetColor(dp)); } else { dp.Graphics.DrawRectangle(_(sr), GetColor(dp)); } SelectableSize = sr.ToSize(); }
/// <summary> /// Drawing main /// </summary> /// <param name="dp"></param> public override void Draw(DrawProperty dp) { var sc = GetScreenPos(dp.Pane); var lsiz = LayoutSize.From(PositionerX(CodeX <Distance> .From(Width), null), PositionerY(null, CodeY <Distance> .From(Height))); var ssiz = ScreenSize.From(dp.Pane, lsiz); var sr = ScreenRect.FromCWH(sc, ssiz.Width, ssiz.Height); SelectableSize = sr.ToSize(); dp.Graphics.DrawRectangle(_(sr), GetColor(dp)); if (IsConnecting) { dp.Graphics.DrawRectangle(_(sr), ConnectingColor, 4f); return; } if (IsSelected) { dp.Graphics.DrawRectangle(_(sr), SelectingColor, 4f); return; } }