public void AddNewShape(Point position) { switch (this.Mode) { case Mode.Select: Select select = new Select(position); this.shapes.Add(select); break; case Mode.FreeHand: FreeLine freeLine = new FreeLine(position, this.Colour); this.undoStack.Push(new List <Shape>(this.shapes)); this.shapes.Add(freeLine); break; case Mode.Line: Line line = new Line(position, this.Colour); this.undoStack.Push(new List <Shape>(this.shapes)); this.shapes.Add(line); break; case Mode.Rectangle: Rectangle rectangle = new Rectangle(position, this.Colour); this.undoStack.Push(new List <Shape>(this.shapes)); this.shapes.Add(rectangle); break; case Mode.Square: Square square = new Square(position, this.Colour); this.undoStack.Push(new List <Shape>(this.shapes)); this.shapes.Add(square); break; case Mode.Ellipse: Ellipse ellipse = new Ellipse(position, this.Colour); this.undoStack.Push(new List <Shape>(this.shapes)); this.shapes.Add(ellipse); break; case Mode.Circle: Circle circle = new Circle(position, this.Colour); this.undoStack.Push(new List <Shape>(this.shapes)); this.shapes.Add(circle); break; case Mode.Polygon: Polygon polygon = new Polygon(position, this.Colour); Line line1 = new Line(position, this.Colour); polygon.addLine(line1); this.undoStack.Push(new List <Shape>(this.shapes)); this.shapes.Add(polygon); break; } this.Invalidate(); // Update the canvas }
public void AddToCurrentShape(Point position) { if (this.shapes.Count == 0) { return; } Shape shape = this.shapes.Last(); if (shape is Select) { Select select = (Select)shape; select.EndPoint = position; } else if (shape is FreeLine) { FreeLine freeLine = (FreeLine)shape; freeLine.Points.Add(position); } else if (shape is Line) { Line line = (Line)shape; line.EndPoint = position; } else if (shape is Rectangle) { Rectangle rectangle = (Rectangle)shape; rectangle.EndPoint = position; } else if (shape is Square) { Square square = (Square)shape; square.EndPoint = position; } else if (shape is Ellipse) { Ellipse ellipse = (Ellipse)shape; ellipse.EndPoint = position; } else if (shape is Circle) { Circle circle = (Circle)shape; circle.EndPoint = position; } else if (shape is Polygon) { Polygon polygon = (Polygon)shape; polygon.getCurrentLine().EndPoint = position; } this.Invalidate(); // Update the canvas }
public static bool FreeLineIntersectsSelect(FreeLine freeLine, Select select) { System.Drawing.Rectangle rect = new System.Drawing.Rectangle(select.StartPoint.X, select.StartPoint.Y, select.Width, select.Height); for (int i = 1; i < freeLine.Points.Count; i++) { if (LineIntersectsRect(freeLine.Points.ElementAt(i - 1), freeLine.Points.ElementAt(i), rect)) { return(true); } } return(false); }