예제 #1
0
        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);
        }
예제 #2
0
        /// <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();
        }
예제 #3
0
        /// <summary>
        /// Updates a shape by redrawing it
        /// </summary>
        /// <param name="g"></param>
        /// <param name="shape"></param>
        public static void UpdateShape(Graphics g, Shape shape)
        {
            //if the index not -1, meaning a shape is not selected
            if (ShapeSelectionForm.index != -1)
            {
                //switch on the shape type
                switch (shape.Type)
                {
                case "Square":
                    Square nonSelectedSquare = new Square(shape.Start, shape.End, shape.Colour);
                    nonSelectedSquare.DrawSqaure(new Pen(shape.Colour));
                    break;

                case "Circle":
                    Circle nonSelectedCircle = new Circle(shape.Colour, shape.Start, shape.End, shape.Radius);
                    nonSelectedCircle.Draw();
                    break;

                case "Triangle":
                    Triangle nonSelectedTriangle = new Triangle(shape.Start, shape.End, shape.Colour);
                    nonSelectedTriangle.DrawTriangle(new Pen(shape.Colour));
                    break;
                }
                //apply the drawing change
                MainForm.ApplyDrawingChange();
            }
        }
예제 #4
0
        /// <summary>
        /// Triggers on mouse move in the panel and
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void CanvasMouseMove(object sender, MouseEventArgs e)
        {
            //  using Graphics g = Canvas.CreateGraphics();
            using Graphics g = Graphics.FromImage(drawingRegion);

            //create a pen object
            mainPen = new Pen(ShapeCreationForm.chosenColour, PenSize);

            // if the mouse used to click was the left button and the CreateSqaure is true
            if (e.Button == MouseButtons.Left && CreateSquare == true)
            {
                //set the endPoint to the positon of the mouse
                endPoint = new Point(e.X, e.Y);

                //create a square object to represent the template of the square
                Square s = new Square(startPoint, endPoint, mainPen.Color);

                //refresh the canvas to prevent creating a vast amount of shapes
                ResetDrawingRegion();

                //draw the square to the canvas
                s.DrawSqaure(mainPen);
            }
            else if (e.Button == MouseButtons.Left && CreateCircle == true)
            {
                endPoint = new Point(e.X, e.Y);

                Circle c = new Circle(mainPen.Color, startPoint, endPoint, Circle.CalculateSize(startPoint.X, startPoint.Y, endPoint.X, endPoint.Y));

                //reset the drawing region
                ResetDrawingRegion();

                //draw the circle
                c.Draw();
            }
            else if (e.Button == MouseButtons.Left && CreateTriangle == true)
            {
                //set the endPoint to the positon of the mouse
                endPoint = new Point(e.X, e.Y);

                //create a square object to represent the template of the square
                Triangle t = new Triangle(startPoint, endPoint, mainPen.Color);

                //refresh the canvas to prevent creating a vast amount of shapes
                ResetDrawingRegion();

                //draw the square to the canvas
                t.DrawTriangle(mainPen);
            }

            //set the background of the canvas to the drawing region
            Canvas.BackgroundImage = drawingRegion;
        }
예제 #5
0
        /// <summary>
        /// Triggers on clicking the delete button
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void Deletebtn_Click(object sender, EventArgs e)
        {
            //draws to the canvas
            using Graphics g = Graphics.FromImage(MainForm.drawingRegion);

            //used to remove a shape from the canvas
            Pen deletePen = new Pen(MainForm.Canvas.BackColor);

            if (index != -1)
            {
                //if the shape list isn't empty and the index is not 1
                if (MainForm.shapes.Count > 0 && index != -1)
                {
                    //switch statement on the shape type
                    switch (MainForm.shapes[index].Type)
                    {
                    case "Square":
                        //square object to delete the old sqaure
                        Square deletetionSquare = new Square(MainForm.shapes[index].Start, MainForm.shapes[index].End, MainForm.shapes[index].Colour);

                        //draw the new square over the old square
                        deletetionSquare.DrawSqaure(deletePen);
                        break;

                    case "Circle":
                        //circle object to delete the old square
                        Circle deletionCircle = new Circle(MainForm.shapes[index].Colour, MainForm.shapes[index].Start, MainForm.shapes[index].End, MainForm.shapes[index].Radius);

                        //deletet the old circle
                        deletionCircle.Delete();
                        break;

                    case "Triangle":
                        //triangle object to delete the old triangle
                        Triangle deletionTrianlge = new Triangle(MainForm.shapes[index].Start, MainForm.shapes[index].End, MainForm.shapes[index].Colour);

                        //delete the old triangle
                        deletionTrianlge.DrawTriangle(deletePen);
                        break;
                    }

                    ShapeMovementForm.RepairAllOtherShapes();

                    //stops the shapes from re-appearing when the canvas is refreshed
                    MainForm.allShapes = (Bitmap)MainForm.drawingRegion.Clone();

                    //remove the shape from the list
                    MainForm.shapes.RemoveAt(index);

                    //set the index to -1 (no shape selected)
                    index = -1;

                    //reset the drawing region bitmap
                    MainForm.ResetDrawingRegion();
                }

                //remove the delete pen from memory
                deletePen.Dispose();
            }
            else
            {
                MessageBox.Show("Select a shape to delete.");
            }
        }