private void AddNewPoint(ImageEditor imgEd, MouseEventArgs e, Polygon polyg) { int pos = Math.Max(imgEd.CurPoints[0], imgEd.CurPoints[1]); if (pos == polyg.VertexCount-1) pos++; Point E = imgEd.ShiftPointIfNotEmpty(new Point(e.X, e.Y)); Graphics g = imgEd.GetGraphics(); polyg.Paint(g, new Pen(Brushes.White, 2)); polyg.AddVertexAt(pos, E); imgEd.ReDraw(); g = imgEd.GetGraphics(); polyg.Paint(g); imgEd.ReDraw(); imgEd.CurPoints.Clear(); }
public override void MouseDown(MouseEventArgs e, ImageEditor imgEd) { if (imgEd.CurPolygon == null) return; Polygon p; int ind = -1; if (WhereIsThePoint(e, imgEd, out p, out ind) == false) return; if (p.VertexCount <= 3) { MessageBox.Show("Количество точек контура минимально. Удаление невозможно"); return; } Point point = new Point(p.GetVertex(ind).X, p.GetVertex(ind).Y); // todo подсветка точки Graphics g = imgEd.GetGraphics(); p.Paint(g, new Pen(Brushes.White, 2)); imgEd.ReDraw(); p.RemoveVertexAt(ind); g = imgEd.GetGraphics(); p.Paint(imgEd.g); imgEd.ReDraw(); }
public override void MouseDown(MouseEventArgs e, ImageEditor imgEd) { Point E = imgEd.ShiftPointIfNotEmpty(new Point(e.X, e.Y)); Graphics g = imgEd.GetGraphics(); imgEd.CurPolygon.AddVertex(E); if (imgEd.CurPolygon.VertexCount > 1) g.DrawLine(new Pen(Brushes.Black, 2), E, new Point(imgEd.CurPolygon.GetVertex(imgEd.CurPolygon.VertexCount - 2).X, imgEd.CurPolygon.GetVertex(imgEd.CurPolygon.VertexCount - 2).Y)); else g.DrawRectangle(new Pen(Brushes.Black, 2), E.X, E.Y, 1, 1); imgEd.ReDraw(); }
public override void KeyPress(KeyPressEventArgs e, ImageEditor imgEd) { if (e.KeyChar == (char)Keys.Space) { if (imgEd.CurPolygon.VertexCount >= 3) { Graphics g = imgEd.GetGraphics(); g.DrawLine(new Pen(Brushes.Black, 2), new Point(imgEd.CurPolygon.GetVertex(0).X, imgEd.CurPolygon.GetVertex(0).Y), new Point(imgEd.CurPolygon.GetVertex(imgEd.CurPolygon.VertexCount - 1).X, imgEd.CurPolygon.GetVertex(imgEd.CurPolygon.VertexCount - 1).Y)); imgEd.ReDraw(); MessageBox.Show("Внешний контур создан"); imgEd.EditingOff(); imgEd.fm.SetbtInnerContour(true); } else MessageBox.Show("Контур не может содержать менее 3 точек!"); } }