public static void PenBrushTool(List <Point> vertices, List <Line> edges, List <ShapeElements> shapeElements, Graphics graph, Pen pen, Panel panel, SenderMethod sender) { if (sender == SenderMethod.PenButtonClick) { RedrawShape(graph, shapeElements, vertices, pen); } if (sender == SenderMethod.DrawPanelClick) { PlacePoint(vertices, graph, panel); if (vertices.Count > 1) { Line line = new Line(vertices[vertices.Count - 2], vertices[vertices.Count - 1]); line.IndexInVertexList = new int[] { vertices.Count - 2, vertices.Count - 1 }; if (!LineUtil.ShapeIntersection("Es können keine schneidenen Kanten eingefügt werden", edges, line)) { line.Draw(pen, graph, vertices, shapeElements); edges.Add(line); shapeElements.Add(line); } else { vertices.Remove(vertices[vertices.Count - 1]); } } } }
/// <summary> /// This function enables the user to choose two vertices, which will be the start /// and the end of a curve. After that he has to pick a third one to give the curves /// side on the shape. /// </summary> public static void CurveBrushTool(List <Point> vertices, List <ShapeElements> shapeElements, List <Line> edges, Graphics graph, Pen blackPen, SenderMethod sender) { if (sender == SenderMethod.CurveButtonClick) { MarkAllVertices(vertices, graph); } else if (sender == SenderMethod.DrawPanelClick) { if (_curveCount == 0) // first Click { _start = ChooseVertex(vertices, 15); MarkAllVertices(vertices, graph, _start); } else if (_curveCount == 1) // second Click { _end = ChooseVertex(vertices, 15); MarkAllVertices(vertices, graph, _start, _end); } else if (_curveCount == 2) // third Click { _curveCount = -1; _direc = ChooseVertex(vertices, 15); List <Point> _curvePoints = new List <Point>(); Curve curve = new Curve(); curve.IndexInVertexList = CreateCurveArray(vertices, _start, _end, _direc); for (int i = 0; i < curve.IndexInVertexList.Length; i++) { _curvePoints.Add(vertices[curve.IndexInVertexList[i]]); } curve.AllPointsOfElement = _curvePoints.ToArray(); for (int j = 0; j < shapeElements.Count; j++) { if (curve.AllPointsOfElement.Contains(shapeElements[j].AllPointsOfElement[1]) && curve.AllPointsOfElement.Contains(shapeElements[j].AllPointsOfElement[0])) { shapeElements.Remove(shapeElements[j--]); } } shapeElements.Add(curve); _curvePoints.Clear(); RedrawShape(graph, shapeElements, vertices, blackPen); } _curveCount++; } }
/// <summary> /// Marks all vertices when the SenderMethod is the click on the tool Button. /// After that the function enables the user to change the position of a chosen vertex. /// The whole shape is redrawn automatically after such an action. /// </summary> public static void MovePointTool(List <Point> vertices, List <ShapeElements> shapeElements, Graphics graph, Pen pen, SenderMethod sender) { if (vertices.Count > 0) { if (sender == SenderMethod.DragButtonClick) { MarkAllVertices(vertices, graph); } else if (sender == SenderMethod.DrawPanelMouseDown) { chosenPoint = ChooseVertex(vertices, 15); if (vertices.Count > chosenPoint) { MarkAllVertices(vertices, graph, chosenPoint); _choiseValid = true; } } else if (sender == SenderMethod.DrawPanelClick) { if (_choiseValid) { _tempPoint = vertices[chosenPoint]; if (chosenPoint != 0 && chosenPoint != vertices.Count - 1) { vertices[chosenPoint] = MousePos; } else { vertices[0] = MousePos; vertices[vertices.Count - 1] = MousePos; } _choiseValid = false; for (int i = 0; i < shapeElements.Count; i++) { for (int j = 0; j < shapeElements[i].IndexInVertexList.Length; j++) { shapeElements[i].AllPointsOfElement[j] = vertices[shapeElements[i].IndexInVertexList[j]]; } } } RedrawShape(graph, shapeElements, vertices, pen); MarkAllVertices(vertices, graph, chosenPoint); } } }