public void DrawLine() { lineArray[lcounter] = new line(x1, y1, x2, y2); lineArray[lcounter].setColor(colour); lcounter++; drawPanel.Invalidate(); }
public Form1() { InitializeComponent(); for (int i = 0; i < 20; i++) { rectangleArray[i] = new rectangle(); } for (int i = 0; i < 20; i++) { ellipseArray[i] = new ellipse(); } for (int i = 0; i < 20; i++) { lineArray[i] = new line(); } for (int i = 0; i < 20; i++) { squiggleArray[i] = new squiggle(); } for (int i = 0; i < 20; i++) { polygonArray[i] = new polygon(); } }
private void drawPanel_MouseUp(object sender, MouseEventArgs e) { if (mode == "Copy") { if (type == "rect") { int xDiff = clickedPoint.X - e.X; int yDiff = clickedPoint.Y - e.Y; rectangleArray[rcounter].setColor(rectangleArray[obj].getColor()); rectangleArray[rcounter].setX(rectangleArray[obj].getX() - xDiff); rectangleArray[rcounter].setY(rectangleArray[obj].getY() - yDiff); rectangleArray[rcounter].setWidth(rectangleArray[obj].getWidth()); rectangleArray[rcounter].setHeight(rectangleArray[obj].getHeight()); } else if (type == "ellips") { int xDiff = clickedPoint.X - e.X; int yDiff = clickedPoint.Y - e.Y; ellipseArray[ecounter].setColor(ellipseArray[obj].getColor()); ellipseArray[ecounter].setX(ellipseArray[obj].getX() - xDiff); ellipseArray[ecounter].setY(ellipseArray[obj].getY() - yDiff); ellipseArray[ecounter].setWidth(ellipseArray[obj].getWidth()); ellipseArray[ecounter].setHeight(ellipseArray[obj].getHeight()); } else if (type == "squig") { Point p = squiggleArray[obj].getPoint(spoint); int xDiff = p.X - e.X; int yDiff = p.Y - e.Y; for (int i = 0; i < squiggleArray[obj].getSize(); i++) { Point l = squiggleArray[obj].getPoint(i); squiggleArray[scounter].setColor(squiggleArray[obj].getColor()); squiggleArray[scounter].setMovePoint((l.X - xDiff), (l.Y - yDiff), i); } drawPanel.Invalidate(); } else if (type == "line") { int xDiff = clickedPoint.X - e.X; int yDiff = clickedPoint.Y - e.Y; Point p = lineArray[obj].getPoint1(); Point l = lineArray[obj].getPoint2(); lineArray[lcounter].setColor(lineArray[obj].getColor()); lineArray[lcounter].setPoint1((p.X - xDiff), (p.Y - yDiff), colour); lineArray[lcounter].setPoint2((l.X - xDiff), (l.Y - yDiff)); drawPanel.Invalidate(); } else if (type == "poly") { int xDiff = clickedPoint.X - e.X; int yDiff = clickedPoint.Y - e.Y; for (int j = 0; j < 20; j++) { Point p = polygonArray[obj].getPoint(j); polygonArray[pcounter].setColor(polygonArray[obj].getColor()); polygonArray[pcounter].setMovePoint((p.X - xDiff), (p.Y - yDiff), j); } } drawPanel.Invalidate(); obj = 0; type = ""; } else if (mode == "Delete") { if (type == "rect") { rectangleArray[obj].setX(0); rectangleArray[obj].setY(0); rectangleArray[obj].setWidth(0); rectangleArray[obj].setHeight(0); rectangleArray[obj].setColor(Color.White); } else if (type == "ellips") { ellipseArray[obj] = new ellipse(); } else if (type == "squig") { squiggleArray[obj] = new squiggle(); } else if (type == "line") { lineArray[obj] = new line(); } else if (type == "poly") { polygonArray[obj] = new polygon(); } drawPanel.Invalidate(); obj = 0; type = ""; } else if (mode == "Move") { if (type == "rect") { int xDiff = clickedPoint.X - e.X; int yDiff = clickedPoint.Y - e.Y; rectangleArray[obj].setX(rectangleArray[obj].getX() - xDiff); rectangleArray[obj].setY(rectangleArray[obj].getY() - yDiff); } else if (type == "ellips") { int xDiff = clickedPoint.X - e.X; int yDiff = clickedPoint.Y - e.Y; ellipseArray[obj].setX(ellipseArray[obj].getX() - xDiff); ellipseArray[obj].setY(ellipseArray[obj].getY() - yDiff); } else if (type == "squig") { Point p = squiggleArray[obj].getPoint(spoint); int xDiff = p.X - e.X; int yDiff = p.Y - e.Y; for (int i = 0; i < squiggleArray[obj].getSize(); i++) { Point l = squiggleArray[obj].getPoint(i); squiggleArray[obj].setMovePoint((l.X - xDiff), (l.Y - yDiff), i); } drawPanel.Invalidate(); } else if (type == "line") { int xDiff = clickedPoint.X - e.X; int yDiff = clickedPoint.Y - e.Y; Point p = lineArray[obj].getPoint1(); Point l = lineArray[obj].getPoint2(); lineArray[obj].setPoint1((p.X - xDiff), (p.Y - yDiff), colour); lineArray[obj].setPoint2((l.X - xDiff), (l.Y - yDiff)); drawPanel.Invalidate(); } else if (type == "poly") { int xDiff = clickedPoint.X - e.X; int yDiff = clickedPoint.Y - e.Y; for (int j = 0; j < 20; j++) { Point p = polygonArray[obj].getPoint(j); polygonArray[obj].setMovePoint((p.X - xDiff), (p.Y - yDiff), j); } } drawPanel.Invalidate(); obj = 0; type = ""; } else if (mode == "Line") { active = false; x2 = e.X; y2 = e.Y; DrawLine(); } else if (mode == "Rectangle") { active = false; point2 = new Point(e.X, e.Y); x2 = e.X; y2 = e.Y; DrawRectangle(); } else if (mode == "Ellipse") { active = false; point2 = new Point(e.X, e.Y); x2 = e.X; y2 = e.Y; DrawEllipse(); } else if (mode == "Freehand") { scounter++; } active = false; }