/// <summary> /// Rotate a square /// </summary> /// <param name="g"></param> private void RotateSquare() { //old square object to delete the old one Square oldSquare = new Square(MainForm.shapes[ShapeSelectionForm.index].Start, MainForm.shapes[ShapeSelectionForm.index].End, MainForm.shapes[ShapeSelectionForm.index].Colour); //square object with rotated points Square rotatedSquare = new Square(RotatePoint(MainForm.shapes[ShapeSelectionForm.index].Start, ShapeCenter), RotatePoint(MainForm.shapes[ShapeSelectionForm.index].End, ShapeCenter), MainForm.shapes[ShapeSelectionForm.index].Colour); //delete the old square oldSquare.DrawSqaure(new Pen(MainForm.Canvas.BackColor)); //draw the rotated square rotatedSquare.HighlightSqaure(new Pen(rotatedSquare.Colour)); //insert the square into the index of the selected shape MainForm.shapes.Insert(ShapeSelectionForm.index, rotatedSquare); //remove the shape after the inserted shape MainForm.shapes.RemoveAt(ShapeSelectionForm.index + 1); //highlight the newly rotated square rotatedSquare.HighlightSqaure(new Pen(rotatedSquare.Colour)); MainForm.ApplyDrawingChange(); }
public void MoveSquareRight() { Square oldSquare = new Square(new Point(MainForm.shapes[ShapeSelectionForm.index].Start.X, MainForm.shapes[ShapeSelectionForm.index].Start.Y), new Point(MainForm.shapes[ShapeSelectionForm.index].End.X, MainForm.shapes[ShapeSelectionForm.index].End.Y), MainForm.shapes[ShapeSelectionForm.index].Colour); Square movedSquare = new Square(new Point(MainForm.shapes[ShapeSelectionForm.index].Start.X + movementIncrement, MainForm.shapes[ShapeSelectionForm.index].Start.Y), new Point(MainForm.shapes[ShapeSelectionForm.index].End.X + movementIncrement, MainForm.shapes[ShapeSelectionForm.index].End.Y), MainForm.shapes[ShapeSelectionForm.index].Colour); oldSquare.DrawSqaure(new Pen(MainForm.Canvas.BackColor, MainForm.PenSize)); movedSquare.HighlightSqaure(new Pen(movedSquare.Colour)); MainForm.shapes.Insert(ShapeSelectionForm.index, movedSquare); MainForm.shapes.RemoveAt(ShapeSelectionForm.index + 1); movedSquare.HighlightSqaure(new Pen(movedSquare.Colour)); CalculateSquareCenter(movedSquare); }
/// <summary> /// Hightlights the relevant shape to show it is selected /// </summary> public static void HighlightShapeInList() { //draws to the canvas of the main form using Graphics g = Graphics.FromImage(MainForm.drawingRegion); //if the shape list is not empty and the index is less than the amount of shapes in the list if (MainForm.shapes.Count > -1 && index < MainForm.shapes.Count) { //if the index is greater than 0, highlight the appropriate shape if (index >= 0) { //switch statement for the shape type switch (MainForm.shapes[index].Type) { case "Square": //square object to replace the old square Square replacementSquare = new Square(MainForm.shapes[index].Start, MainForm.shapes[index].End, MainForm.shapes[index].Colour); //draw the replacement square with the highlight pen replacementSquare.HighlightSqaure(new Pen(replacementSquare.Colour)); //calculate the centre of the new square for rotation ShapeMovementForm.CalculateSquareCenter(replacementSquare); break; case "Circle": //circle object to replace the old circle Circle replacementCircle = new Circle(MainForm.shapes[index].Colour, MainForm.shapes[index].Start, MainForm.shapes[index].End, MainForm.shapes[index].Radius); //draw the circle replacementCircle.Highlight(MainForm.shapes[ShapeSelectionForm.index].Colour); break; case "Triangle": //triangle object to replace the old one Triangle replacementTriangle = new Triangle(MainForm.shapes[index].Start, MainForm.shapes[index].End, MainForm.shapes[index].Colour); //draw the replacement triangle replacementTriangle.HighlightTriangle(new Pen(replacementTriangle.Colour)); //calculate the centre of the new triangle ShapeMovementForm.CalculateTriangleCentre(replacementTriangle); break; } //reset the drawing region MainForm.ResetDrawingRegion(); } } }