コード例 #1
0
        public TransformBezierControlPoints(BezierControlPoint[] points)
        {
            DefaultPoints = new BezierControlPoint[points.Length];
            for (int i = 0; i < points.Length; i++)
            {
                DefaultPoints[i] = points[i].Clone();
            }
            var   first  = DefaultPoints[0] as BezierControlPoint;
            float top    = first.Second.Y;
            float left   = first.Second.X;
            float bottom = first.Second.Y;
            float right  = first.Second.X;

            for (int i = 1; i < DefaultPoints.Length; i++)
            {
                var temp = DefaultPoints[i] as BezierControlPoint;
                BezierCaliculate.GetArea(first, temp, out float minx, out float maxx, out float miny, out float maxy);
                top    = Math.Min(top, miny);
                bottom = Math.Max(bottom, maxy);
                left   = Math.Min(left, minx);
                right  = Math.Max(right, maxx);
                first  = temp;
            }
            TransRec = new TransformRectangle(
                new PointF(left, top),
                new PointF(right, top),
                new PointF(left, bottom),
                new PointF(right, bottom)
                );
        }
コード例 #2
0
        private void DrawBezeier(PointF p1, PointF p2, PointF p3, PointF p4, Graphics g)
        {
            PointF lastbezeirpoint, bezeirpoint;

            lastbezeirpoint = p1;
            var count = BezierCaliculate.AboutBezeirCount(ref p1, ref p2, ref p3, ref p4);

            for (int i = count; i >= 0; i--)
            {
                float t = (float)i / count;
                bezeirpoint = BezierCaliculate.GetBezeirPoint(ref p1, ref p2, ref p3, ref p4, ref t);
                g.DrawLine(Pens.Black, lastbezeirpoint, bezeirpoint);
                lastbezeirpoint = bezeirpoint;
            }
        }
コード例 #3
0
        private void DrawBezeier(PointF p1, PointF p2, PointF p3, PointF p4, IBezierDrawContext context)
        {
            PointF lastbezeirpoint, bezeirpoint;

            lastbezeirpoint = p1;
            var count = BezierCaliculate.AboutBezeirCount(ref p1, ref p2, ref p3, ref p4);

            for (int i = count; i >= 0; i--)
            {
                float t = (float)i / count;
                bezeirpoint = BezierCaliculate.GetBezeirPoint(ref p1, ref p2, ref p3, ref p4, ref t);
                context.DrawLine(Color.Black, lastbezeirpoint, bezeirpoint);
                lastbezeirpoint = bezeirpoint;
            }
        }
コード例 #4
0
        private void BezierRatioDrawer_MouseMove(object sender, MouseEventArgs e)
        {
            float x = e.X, y = e.Y;

            if (x < 0)
            {
                x = 0;
            }
            if (x > this.Width)
            {
                x = this.Width;
            }
            if (y < 0)
            {
                y = 0;
            }
            if (y > this.Height)
            {
                y = this.Height;
            }

            var mousepos = new PointF(x, y);

            if (selected != null)
            {
                if (selected == bcps[0])
                {
                    var f  = new PointF(mousepos.X - selected.Second.X, mousepos.Y - selected.Second.Y);
                    var nv = BezierCaliculate.GetNormalizePoint(f);
                    selected.ThirdDirection = nv;
                    selected.ThirdLength    = GetLength(f);
                    IsLinear = false;
                    DrawandRefresh();
                }
                else if (selected == bcps[1])
                {
                    var f  = new PointF(mousepos.X - selected.Second.X, mousepos.Y - selected.Second.Y);
                    var nv = BezierCaliculate.GetNormalizePoint(f);
                    selected.FirstDirection = nv;
                    selected.FirstLength    = GetLength(f);
                    IsLinear = false;
                    DrawandRefresh();
                }
            }
        }
コード例 #5
0
 private void NormalMouseDown(PointF downpos, bool isLeftButton, Keys modifierKeys)
 {
     if ((modifierKeys & Keys.Control) == Keys.Control)
     {
         bool foundanchor = false;
         if (SelectedPoint != null && SelectedPoint.ValidFirst && SelectedPoint.ValidThird)
         {
             if (IsInside(SelectedPoint.First, downpos))
             {
                 foundanchor = true;
                 changedFlag = true;
                 mode        = Mode.ChangeFirst;
             }
             else if (IsInside(SelectedPoint.Third, downpos))
             {
                 foundanchor = true;
                 changedFlag = true;
                 mode        = Mode.ChangeThird;
             }
         }
         if (!foundanchor)
         {
             SelectedPoint = null;
             for (int i = 0; i < data.Count; i++)
             {
                 var bcp = data[i] as BezierControlPoint;
                 if (IsInside(bcp.Second, downpos))
                 {
                     SelectedPoint = bcp;
                     changedFlag   = true;
                     mode          = Mode.Move;
                     break;
                 }
             }
         }
     }
     else if ((modifierKeys & Keys.Shift) == Keys.Shift)
     {
         SelectedPoint = null;
         for (int i = 0; i < data.Count; i++)
         {
             var bcp = data[i] as BezierControlPoint;
             if (IsInside(bcp.Second, downpos))
             {
                 SelectedPoint = bcp;
                 changedFlag   = true;
                 mode          = Mode.RestrictMove;
                 break;
             }
         }
     }
     else if ((modifierKeys & Keys.Alt) == Keys.Alt)
     {
         bool foundanchor = false;
         if (SelectedPoint != null && SelectedPoint.ValidFirst && SelectedPoint.ValidThird)
         {
             if (IsInside(SelectedPoint.First, downpos))
             {
                 foundanchor = true;
                 changedFlag = true;
                 mode        = Mode.ChangeOnlyFirst;
             }
             else if (IsInside(SelectedPoint.Third, downpos))
             {
                 foundanchor = true;
                 changedFlag = true;
                 mode        = Mode.ChangeOnlyThird;
             }
         }
         if (!foundanchor)
         {
             SelectedPoint = null;
             for (int i = 0; i < data.Count; i++)
             {
                 var bcp = data[i] as BezierControlPoint;
                 if (IsInside(bcp.Second, downpos))
                 {
                     SelectedPoint      = bcp;
                     bcp.ValidFirst     = false;
                     bcp.ValidThird     = false;
                     bcp.FirstDirection = new PointF(0, 0);
                     bcp.FirstLength    = 0;
                     bcp.ThirdDirection = new PointF(0, 0);
                     bcp.ThirdLength    = 0;
                     mode        = Mode.ChangeBoth;
                     changedFlag = true;
                     break;
                 }
             }
         }
     }
     else if (isLeftButton)
     {
         BezierControlPoint next = null;
         if (IsOnLine(downpos, out BezierControlPoint previous, out float t))
         {
             if (data.Count >= 2 && previous == data[0] && data[0] != data[data.Count - 1] && t >= 0.95)
             {
                 //loop
                 SelectedPoint = previous;
                 data.Add(previous);
                 changedFlag = true;
                 OnEdited(EditType.Add, data.Count - 1);
             }
             else
             {
                 var index = data.IndexOf(previous);
                 if (index < data.Count - 1)
                 {
                     next = data[index + 1] as BezierControlPoint;
                 }
                 BezierCaliculate.GetDevidedBeziers(previous, next, t, out BezierControlPoint bcp1, out BezierControlPoint bcp2, out BezierControlPoint bcp3);
                 var previousIndex = data.IndexOf(previous);
                 data[previousIndex]     = bcp1;
                 data[previousIndex + 1] = bcp3;
                 data.Insert(previousIndex + 1, bcp2);
                 SelectedPoint = bcp2;
                 changedFlag   = true;
                 OnEdited(EditType.Add, previousIndex + 1);
             }
         }
         else
         {
             var bcp = new BezierControlPoint
             {
                 Second = downpos
             };
             data.Add(bcp);
             SelectedPoint = bcp;
             changedFlag   = true;
             OnEdited(EditType.Add, data.Count - 1);
         }
     }
コード例 #6
0
        private PointF GetNormalizePoint(PointF p1, PointF p2)
        {
            var temp = new PointF(p1.X + p2.X, p1.Y + p2.Y);

            return(BezierCaliculate.GetNormalizePoint(temp));
        }