public void DrawMyRectangle(PaintEventArgs e, MyRectangle selectedRectange, string btnName) { if (lines.Count > 0 && (lines.First().start == lines.Last().end)) { if (selectedRectange != this) { e.Graphics.FillPolygon(Brushes.LightGray, lines.Select(it => it.start).ToArray()); } else { e.Graphics.FillPolygon(Brushes.Gray, lines.Select(it => it.start).ToArray()); } } foreach (MyLine line in lines) { line.DrawMyLine(e, btnName); } }
public Form1() { InitializeComponent(); panel2 = HolderPanel; actualCreatingRectangle = new MyRectangle(); createingLine = false; rectangles = new List <MyRectangle>(); startPointRectangle = Point.Empty; actualCreatingLine = new MyLine(Point.Empty, Point.Empty); SelectedButton = create_polygons_button; leftMouseDown = false; actualEditedRectangle = null; actualMovingPointIndex = -1; startPressedPosForMoveLine = Point.Empty; rectangleWithSelectedEdge = null; pressedLineIndex = -1; activeAlgorythm = system_method_radiobutton; }
private void HolderPanel_MouseUp(object sender, MouseEventArgs e) { if (SelectedButton == move_polygons_button) { SelectedRectangle = null; leftMouseDown = false; } else if (SelectedButton == move_vertexes_button) { actualMovingPointIndex = -1; actualEditedRectangle = null; } else if (SelectedButton == move_edges_button) { startPressedPosForMoveLine = Point.Empty; rectangleWithSelectedEdge = null; pressedLineIndex = -1; } }
private void Panel2_MouseDown(object sender, MouseEventArgs e) { if (SelectedButton == create_polygons_button) { if (createingLine) { if (checkClickPos(startPointRectangle, e.Location)) { //reset all tmp values for the next polygon if (startPointRectangle != actualCreatingLine.start) { actualCreatingRectangle.Add(new MyLine(actualCreatingLine.start, startPointRectangle)); rectangles.Add(actualCreatingRectangle); actualCreatingLine.start = Point.Empty; actualCreatingLine.end = Point.Empty; actualCreatingRectangle = new MyRectangle(); createingLine = false; startPointRectangle = Point.Empty; panel2.Invalidate(); } return; } actualCreatingRectangle.Add(new MyLine(actualCreatingLine.start, e.Location)); actualCreatingLine.start = e.Location; } else { startPointRectangle = actualCreatingLine.start = actualCreatingLine.end = e.Location; createingLine = true; actualCreatingRectangle = new MyRectangle(); } } else if (SelectedButton == move_polygons_button) { int i; for (i = rectangles.Count - 1; i >= 0; i--) { if (rectangles[i].checkPointInside(e.Location)) { startPressedPosForMovePolygons = e.Location; SelectedRectangle = rectangles[i]; break; } } leftMouseDown = true; } else if (SelectedButton == delete_polygons_button) { int i; for (i = rectangles.Count - 1; i >= 0; i--) { if (rectangles[i].checkPointInside(e.Location)) { rectangles.RemoveAt(i); break; } } } else if (SelectedButton == add_vertexes_button) { foreach (MyRectangle rect in rectangles) { rect.addVertexOnThePressedLine(e.Location); } } else if (SelectedButton == move_vertexes_button) { bool isFinded = false; for (int i = rectangles.Count - 1; i >= 0 && !isFinded; i--) { for (int j = 0; j < rectangles[i].lines.Count; j++) { Point tmp; if (checkClickPos(tmp = rectangles[i].lines[j].start, e.Location)) { actualEditedRectangle = rectangles[i]; actualMovingPointIndex = j; isFinded = true; break; } } } } else if (SelectedButton == delete_vertexes_button) { bool isFinded = false; for (int i = rectangles.Count - 1; i >= 0 && !isFinded; i--) { for (int j = 0; j < rectangles[i].lines.Count; j++) { Point tmp; if (checkClickPos(tmp = rectangles[i].lines[j].start, e.Location)) { if (!rectangles[i].removeVertex(tmp)) { rectangles.RemoveAt(i); } isFinded = true; break; } } } } else if (SelectedButton == move_edges_button) { bool isFound = false; for (int i = rectangles.Count - 1; i >= 0 && !isFound; i--) { for (int j = 0; j < rectangles[i].lines.Count; j++) { if (rectangles[i].lines[j].checkPressedLine(e.Location)) { startPressedPosForMoveLine = e.Location; rectangleWithSelectedEdge = rectangles[i]; pressedLineIndex = j; isFound = true; break; } } } leftMouseDown = true; } else if (SelectedButton == edit_horisontal_rule_button) { if (e.Button == MouseButtons.Left) { bool isFound = false; for (int i = rectangles.Count - 1; i >= 0 && !isFound; i--) { for (int j = 0; j < rectangles[i].lines.Count; j++) { if (rectangles[i].lines[j].checkPressedLine(e.Location)) { if (rectangles[i].lines[j].rule == null && rectangles[i].lines[(rectangles[i].lines.Count + j - 1) % rectangles[i].lines.Count].rule?.GetType() != typeof(HorizontalRule) && rectangles[i].lines[(j + 1) % rectangles[i].lines.Count].rule?.GetType() != typeof(HorizontalRule) ) { rectangles[i].addRule(new HorizontalRule(), j); } isFound = true; break; } } } } else if (e.Button == MouseButtons.Right) { bool isFound = false; for (int i = rectangles.Count - 1; i >= 0 && !isFound; i--) { for (int j = 0; j < rectangles[i].lines.Count; j++) { if (rectangles[i].lines[j].checkPressedLine(e.Location)) { rectangles[i].deleteRule(j); isFound = true; break; } } } } } else if (SelectedButton == edit_vertical_rule_button) { if (e.Button == MouseButtons.Left) { bool isFound = false; for (int i = rectangles.Count - 1; i >= 0 && !isFound; i--) { for (int j = 0; j < rectangles[i].lines.Count; j++) { if (rectangles[i].lines[j].checkPressedLine(e.Location)) { if (rectangles[i].lines[j].rule == null && rectangles[i].lines[(rectangles[i].lines.Count + j - 1) % rectangles[i].lines.Count].rule?.GetType() != typeof(VerticalRule) && rectangles[i].lines[(j + 1) % rectangles[i].lines.Count].rule?.GetType() != typeof(VerticalRule) ) { rectangles[i].addRule(new VerticalRule(), j); } isFound = true; break; } } } } else if (e.Button == MouseButtons.Right) { bool isFound = false; for (int i = rectangles.Count - 1; i >= 0 && !isFound; i--) { for (int j = 0; j < rectangles[i].lines.Count; j++) { if (rectangles[i].lines[j].checkPressedLine(e.Location)) { rectangles[i].deleteRule(j); isFound = true; break; } } } } } else if (SelectedButton == edit_angle_rule) { } panel2.Invalidate(); }