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 MainCanvas_MouseMove(object sender, MouseEventArgs e) { if (EditMode == EditMode.DrawRelation) { mouseCurrentPoint = new Point(e.X, e.Y); MainCanvas.Refresh(); } else if (EditMode == EditMode.Normal) { var x = (int)((e.X - MainCanvas.AutoScrollPosition.X) / Zoom); var y = (int)((e.Y - MainCanvas.AutoScrollPosition.Y) / Zoom); if (e.Button != MouseButtons.None) { if (currentBoundingItem == null) { if (isPanning) { int dx = mouseDownPoint.X - e.X; int dy = mouseDownPoint.Y - e.Y; var newPos = new Point(mouseDownAutoscrollPoint.X + dx, mouseDownAutoscrollPoint.Y + dy); MainCanvas.AutoScrollPosition = newPos; Cursor = Cursors.SizeAll; } } else { var shape = (Shape)currentBoundingItem.Target; var args = new ShapeMouseEventArgs { BoundingItem = currentBoundingItem, X = x, Y = y, Button = e.Button, Sender = this, GridSize = GridSize, SnapToGrid = SnapToGrid }; shape.OnMouseMove(args); if (args.Redraw) { MainCanvas.Refresh(); } } } else { for (int i = BoundingItemes.Count - 1; i >= 0; i--) { BoundingItem bitem = BoundingItemes[i]; if (bitem.HitTest(x, y)) { if (bitem.Target is Shape) { var shape = (Shape)bitem.Target; var args = new ShapeMouseEventArgs { BoundingItem = bitem, X = x, Y = y, Button = e.Button, Sender = this }; shape.OnMouseMove(args); if (args.Redraw) { MainCanvas.Refresh(); } } return; } } } } }
private void MainCanvas_MouseUp(object sender, MouseEventArgs e) { var x = (int)((e.X - MainCanvas.AutoScrollPosition.X) / Zoom); var y = (int)((e.Y - MainCanvas.AutoScrollPosition.Y) / Zoom); if (EditMode == EditMode.DrawRelation) { relationEnd = null; for (int i = BoundingItemes.Count - 1; i >= 0; i--) { BoundingItem bitem = BoundingItemes[i]; if (bitem.HitTest(x, y)) { if (bitem.Target is Shape) { relationEnd = bitem.Target as Shape; } } } endDrawRelation(relationStart, relationEnd); //end drawing EditMode = EditMode.Normal; MainCanvas.Refresh(); } else if (EditMode == EditMode.Normal) { Cursor = Cursors.Default; currentBoundingItem = null; isPanning = false; for (int i = BoundingItemes.Count - 1; i >= 0; i--) { BoundingItem bitem = BoundingItemes[i]; if (bitem.HitTest(x, y)) { if (bitem.Target is Shape) { var shape = (Shape)bitem.Target; var args = new ShapeMouseEventArgs { BoundingItem = bitem, X = x, Y = y, Button = e.Button, Sender = this, GridSize = GridSize, SnapToGrid = SnapToGrid }; shape.OnMouseUp(args); if (args.Redraw) { Refresh(); } } return; } } } }
private void MainCanvas_MouseDown(object sender, MouseEventArgs e) { if (add_vertex.Checked) { Vertex v; if (!FinishedAction) { DrawLine(highlighted.PictureBox.Location.X + 4, highlighted.PictureBox.Location.Y + 4, e.X + 4, e.Y + 4, Color.Purple); v = new Vertex(e.X, e.Y, highlighted, null, (Control)sender); highlighted.NextVertex = v; v.PictureBox.MouseDown += new System.Windows.Forms.MouseEventHandler(Vertex_MouseDown); v.PictureBox.MouseUp += PictureBox_MouseUp; Polygons.Last().Add(v); } else { if (((Bitmap)MainCanvas.Image).GetPixel(e.Location.X, e.Location.Y).ToArgb() == Color.Purple.ToArgb()) //add vertex to edge { int pol = DetermineEdge(e.Location); DeleteRelation(highlighted); v = new Vertex((highlighted.PictureBox.Location.X + highlighted.NextVertex.PictureBox.Location.X) / 2, (highlighted.PictureBox.Location.Y + highlighted.NextVertex.PictureBox.Location.Y) / 2, highlighted, highlighted.NextVertex, (Control)sender); v.PictureBox.MouseDown += new System.Windows.Forms.MouseEventHandler(Vertex_MouseDown); v.PictureBox.MouseUp += PictureBox_MouseUp; highlighted.NextVertex.PreviousVertex = v; highlighted.NextVertex = v; Polygons[pol].Add(v); } else { v = new Vertex(e.X, e.Y, null, null, (Control)sender); v.PictureBox.MouseDown += new System.Windows.Forms.MouseEventHandler(Vertex_MouseDown); v.PictureBox.MouseUp += PictureBox_MouseUp; Polygons.Add(new List <Vertex> { v }); FinishedAction = false; } } UpdateHighlighted(v); MainCanvas.Refresh(); } else if (move_vertex_edge.Checked) { if (((Bitmap)MainCanvas.Image).GetPixel(e.Location.X, e.Location.Y).ToArgb() == MainCanvas.BackColor.ToArgb()) //not edge => moving Polygon { MovingMode = 3; } else //moving edge { MovingMode = 2; DetermineEdge(e.Location); } PrevoiusLocation = e.Location; timer = new Timer(); timer.Interval = 10; timer.Tick += Timer_Tick; timer.Start(); } else if (parallel.Checked) { if (((Bitmap)MainCanvas.Image).GetPixel(e.Location.X, e.Location.Y).ToArgb() == MainCanvas.BackColor.ToArgb()) { return; } Vertex temp = highlighted; int ind = DetermineEdge(e.Location); if (highlighted.Relation != null) { temp.PictureBox.BackColor = Color.Blue; temp.NextVertex.PictureBox.BackColor = Color.Blue; UpdateHighlighted(highlighted); FinishedAction = true; MessageBox.Show("Relation already set"); return; } if (FinishedAction) //first edge in relation { FinishedAction = false; highlighted.PictureBox.BackColor = Color.Yellow; highlighted.NextVertex.PictureBox.BackColor = Color.Yellow; } else//second edge in relation { if (temp == highlighted) { return; } if (temp.NextVertex == highlighted || highlighted.NextVertex == temp) { FinishedAction = true; temp.PictureBox.BackColor = Color.Blue; temp.NextVertex.PictureBox.BackColor = Color.Blue; UpdateHighlighted(highlighted); MessageBox.Show("Incidental edges cannot be parallel"); return; } bool already = SetParallel(temp, highlighted); temp.Relation = new EdgeRelation(1, highlighted, temp, MainCanvas); temp.Relation.symbol.MouseDown += Symbol_MouseDown; highlighted.Relation = new EdgeRelation(1, temp, highlighted, MainCanvas); highlighted.Relation.symbol.MouseDown += Symbol_MouseDown; FinishedAction = true; temp.PictureBox.BackColor = Color.Blue; temp.NextVertex.PictureBox.BackColor = Color.Blue; UpdateHighlighted(highlighted); if (!already) { if (!CorrectRelations(highlighted.NextVertex, ind)) { DeleteRelation(highlighted); CorrectRelations(highlighted.NextVertex, ind); ReloadCanvas(); MessageBox.Show("Relation could not be set"); } } ReloadCanvas(); } } else if (equall.Checked) { if (((Bitmap)MainCanvas.Image).GetPixel(e.Location.X, e.Location.Y).ToArgb() == MainCanvas.BackColor.ToArgb()) { return; } Vertex temp = highlighted; int ind = DetermineEdge(e.Location); if (highlighted.Relation != null) { FinishedAction = true; temp.PictureBox.BackColor = Color.Blue; temp.NextVertex.PictureBox.BackColor = Color.Blue; UpdateHighlighted(highlighted); MessageBox.Show("Relation already set"); return; } if (FinishedAction) //first edge in relation { FinishedAction = false; highlighted.PictureBox.BackColor = Color.Green; highlighted.NextVertex.PictureBox.BackColor = Color.Green; } else//second edge in relation { if (temp == highlighted) { return; } bool already = SetEquall(temp, highlighted); temp.Relation = new EdgeRelation(2, highlighted, temp, MainCanvas); temp.Relation.symbol.MouseDown += Symbol_MouseDown; highlighted.Relation = new EdgeRelation(2, temp, highlighted, MainCanvas); highlighted.Relation.symbol.MouseDown += Symbol_MouseDown; temp.PictureBox.BackColor = Color.Blue; temp.NextVertex.PictureBox.BackColor = Color.Blue; FinishedAction = true; UpdateHighlighted(highlighted); if (!already) { if (!CorrectRelations(highlighted.NextVertex, ind)) { DeleteRelation(highlighted); CorrectRelations(highlighted.NextVertex, ind); ReloadCanvas(); MessageBox.Show("Relation could not be set"); } } ReloadCanvas(); } } else if (delete_relation.Checked) { if (((Bitmap)MainCanvas.Image).GetPixel(e.Location.X, e.Location.Y).ToArgb() == MainCanvas.BackColor.ToArgb()) { return; } DetermineEdge(e.Location); DeleteRelation(highlighted); } }
private void MainCanvas_MouseMove(object sender, MouseEventArgs e) { if (EditMode == EditMode.DrawRelation) { mouseCurrentPoint = new Point(e.X, e.Y); MainCanvas.Refresh(); } else if (EditMode == EditMode.Normal) { var x = (int)((e.X - MainCanvas.AutoScrollPosition.X) / Zoom); var y = (int)((e.Y - MainCanvas.AutoScrollPosition.Y) / Zoom); if (e.Button != MouseButtons.None) { if (currentBoundingBox == null) { if (isPanning) { int dx = mouseDownPoint.X - e.X; int dy = mouseDownPoint.Y - e.Y; var newPos = new Point(mouseDownAutoscrollPoint.X + dx, mouseDownAutoscrollPoint.Y + dy); MainCanvas.AutoScrollPosition = newPos; Cursor = Cursors.SizeAll; } } else { var shape = (Shape)currentBoundingBox.Target; var args = new ShapeMouseEventArgs(); args.BoundingBox = currentBoundingBox; args.X = x; args.Y = y; args.Button = e.Button; args.Sender = this; args.GridSize = GridSize; args.SnapToGrid = SnapToGrid; shape.OnMouseMove(args); if (args.Redraw) { MainCanvas.Refresh(); } } } else { for (int i = BoundingBoxes.Count - 1; i >= 0; i--) { BoundingBox bbox = BoundingBoxes[i]; if (bbox.Bounds.Contains(x, y)) { if (bbox.Target is Shape) { var shape = (Shape)bbox.Target; var args = new ShapeMouseEventArgs(); args.BoundingBox = bbox; args.X = x; args.Y = y; args.Button = e.Button; args.Sender = this; shape.OnMouseMove(args); if (args.Redraw) { MainCanvas.Refresh(); } } return; } } } } }
private void MainCanvas_MouseUp(object sender, MouseEventArgs e) { var x = (int)((e.X - MainCanvas.AutoScrollPosition.X) / Zoom); var y = (int)((e.Y - MainCanvas.AutoScrollPosition.Y) / Zoom); if (EditMode == EditMode.DrawRelation) { relationEnd = null; for (int i = BoundingBoxes.Count - 1; i >= 0; i--) { BoundingBox bbox = BoundingBoxes[i]; if (bbox.Bounds.Contains(x, y)) { if (bbox.Target is Shape) { relationEnd = bbox.Target as Shape; } } } endDrawRelation(relationStart, relationEnd); //end drawing EditMode = EditMode.Normal; MainCanvas.Refresh(); } else if (EditMode == EditMode.Normal) { Cursor = Cursors.Default; currentBoundingBox = null; isPanning = false; for (int i = BoundingBoxes.Count - 1; i >= 0; i--) { BoundingBox bbox = BoundingBoxes[i]; if (bbox.Bounds.Contains(x, y)) { if (bbox.Target is Shape) { var shape = (Shape)bbox.Target; var args = new ShapeMouseEventArgs(); args.BoundingBox = bbox; args.X = x; args.Y = y; args.Button = e.Button; args.Sender = this; args.GridSize = GridSize; args.SnapToGrid = SnapToGrid; shape.OnMouseUp(args); if (args.Redraw) { Refresh(); } } return; } } } }