private void Vertex_MouseDown(object sender, MouseEventArgs e) { Vertex v = (Vertex)((Control)sender).Tag; if (add_vertex.Checked) { FinishedAction = true; if (v.PreviousVertex != null || Polygons.Last().Count < 3) //wrong or not enough vertices { if (Polygons.Last().Contains(highlighted)) { if (Polygons.Count > 1) { UpdateHighlighted(Polygons[Polygons.Count - 2][0]); } else { UpdateHighlighted(null); } } foreach (var item in Polygons.Last()) { item.PictureBox.Dispose(); } Polygons.RemoveAt(Polygons.Count - 1); ReloadCanvas(); return; } DrawLine(highlighted.PictureBox.Location.X + 4, highlighted.PictureBox.Location.Y + 4, ((Control)sender).Location.X + 4, ((Control)sender).Location.Y + 4, Color.Purple); v.PreviousVertex = highlighted; highlighted.NextVertex = v; UpdateHighlighted(v); MainCanvas.Refresh(); } else if (delete_vertex.Checked) { DeleteVertex(v); ReloadCanvas(); } else if (move_vertex_edge.Checked) { MovingMode = 1; UpdateHighlighted(v); PrevoiusLocation = MainCanvas.PointToClient(Cursor.Position); timer = new Timer(); timer.Interval = 10; timer.Tick += Timer_Tick; timer.Start(); } }
private void Timer_Tick(object sender, EventArgs e) { if (MovingMode == 0 || highlighted == null) { return; } Point p = MainCanvas.PointToClient(Cursor.Position); int dx = p.X - PrevoiusLocation.X; int dy = p.Y - PrevoiusLocation.Y; if (p.X < 0 || p.Y < 0 || p.X + 9 > MainCanvas.Width || p.Y + 9 > MainCanvas.Height) { timer.Stop(); MovingMode = 0; } PrevoiusLocation = new Point(PrevoiusLocation.X + dx, PrevoiusLocation.Y + dy); highlighted.MoveVertex(dx, dy); if (MovingMode == 1) { Vertex temp = highlighted.PreviousVertex; while (temp.Relation != null && temp != highlighted) { temp.MoveVertex(dx, dy); temp = temp.PreviousVertex; } if (temp != highlighted && highlighted.Relation != null)//not the full circle { temp = highlighted.NextVertex; while (temp.Relation != null && temp != highlighted) { temp.MoveVertex(dx, dy); temp = temp.NextVertex; } temp.MoveVertex(dx, dy); } } if (MovingMode == 2) //moving whole edge=> highlighted.nextvertex too { highlighted.NextVertex.MoveVertex(dx, dy); Vertex temp = highlighted.PreviousVertex; while (temp.Relation != null && temp != highlighted.NextVertex) { temp.MoveVertex(dx, dy); temp = temp.PreviousVertex; } if (temp != highlighted.NextVertex && highlighted.NextVertex.Relation != null)//not the full circle { temp = highlighted.NextVertex.NextVertex; while (temp.Relation != null && temp != highlighted) { temp.MoveVertex(dx, dy); temp = temp.NextVertex; } temp.MoveVertex(dx, dy); } } else if (MovingMode == 3) { Vertex temp = highlighted.NextVertex; while (temp != highlighted) { temp.MoveVertex(dx, dy); temp = temp.NextVertex; } } ReloadCanvas(); }