Пример #1
0
 public void AddPointTest()
 {
     Paint.Shapes.Rectangle rectangle = new Paint.Shapes.Rectangle();
     for (int i = 0; i < 3; i++)
     {
         Assert.AreEqual(true, rectangle.AddPoint(new Point(0, i)));
     }
     Assert.IsFalse(rectangle.IsCompleted());
     Assert.AreEqual(false, rectangle.AddPoint(new Point(0, 1234)));
     Assert.IsTrue(rectangle.IsCompleted());
 }
Пример #2
0
        public void CenterTest()
        {
            Paint.Shapes.Rectangle rectangle = new Paint.Shapes.Rectangle
            {
                Points = new List <Point> {
                    new Point(0, 0), new Point(10, 0), new Point(0, 4), new Point(10, 4)
                }
            };
            var center = rectangle.Center();

            Assert.AreEqual(5, center.X);
            Assert.AreEqual(2, center.Y);
        }
Пример #3
0
        private void KhungVe_MouseDown(object sender, MouseEventArgs e)
        {
            if (currentShape == CurrentShape.NoDrawing)
            {
                if (isControlKeyPress)
                {
                    for (int i = 0; i < shapes.Count; i++)
                    {
                        if (shapes[i].IsHit(e.Location))
                        {
                            shapes[i].IsSelected = !shapes[i].IsSelected;
                            KhungVe.Invalidate();
                            break;
                        }
                    }
                }
                else
                {
                    shapes.ForEach(shape => shape.IsSelected = false);
                    KhungVe.Invalidate();

                    for (int i = 0; i < shapes.Count; i++)
                    {
                        if (shapes[i].IsHit(e.Location))
                        {
                            selectedShape        = shapes[i];
                            shapes[i].IsSelected = true;

                            KhungVe.Invalidate();
                            break;
                        }
                    }

                    if (selectedShape != null)
                    {
                        isMovingShape = true;
                        previousPoint = e.Location;
                    }
                    else
                    {
                        isMouseSelect  = true;
                        selectedRegion = new System.Drawing.Rectangle(e.Location, new Size(0, 0));
                    }
                }
            }
            else
            {
                isMouseDown = true;
                shapes.ForEach(shape => shape.IsSelected = false);

                if (currentShape == CurrentShape.Line)
                {
                    Line line = new Line
                    {
                        Begin     = e.Location,
                        LineWidth = cbSize.SelectedIndex,
                        Color     = btnColors.BackColor,
                        DashStyle = DashStyle.Solid
                    };
                    shapes.Add(line);
                }
                else if (currentShape == CurrentShape.Rectangle)
                {
                    Shapes.Rectangle rectangle = new Shapes.Rectangle
                    {
                        Begin     = e.Location,
                        LineWidth = cbSize.SelectedIndex,
                        Color     = btnColors.BackColor,
                        DashStyle = DashStyle.Solid
                    };



                    shapes.Add(rectangle);
                }
                else if (currentShape == CurrentShape.Ellipse)
                {
                    Ellipse ellipse = new Ellipse
                    {
                        Begin     = e.Location,
                        LineWidth = cbSize.SelectedIndex,
                        Color     = btnColors.BackColor,
                        DashStyle = DashStyle.Solid
                    };



                    shapes.Add(ellipse);
                }
                else if (currentShape == CurrentShape.Square)
                {
                    Square square = new Square
                    {
                        Begin     = e.Location,
                        LineWidth = cbSize.SelectedIndex,
                        Color     = btnColors.BackColor,
                        DashStyle = DashStyle.Solid
                    };



                    shapes.Add(square);
                }
                else if (currentShape == CurrentShape.Circle)
                {
                    Circle circle = new Circle
                    {
                        Begin     = e.Location,
                        LineWidth = cbSize.SelectedIndex,
                        Color     = btnColors.BackColor,
                        DashStyle = DashStyle.Solid
                    };



                    shapes.Add(circle);
                }
                else if (currentShape == CurrentShape.Polygon)
                {
                    if (!isDrawPolygon)
                    {
                        Polygon polygon = new Polygon
                        {
                            LineWidth = cbSize.SelectedIndex,
                            Color     = btnColors.BackColor,
                            DashStyle = DashStyle.Solid
                        };

                        polygon.Points.Add(e.Location);
                        polygon.Points.Add(e.Location);

                        shapes.Add(polygon);

                        isDrawPolygon = true;
                    }
                    else
                    {
                        Polygon polygon = shapes[shapes.Count - 1] as Polygon;
                        polygon.Points[polygon.Points.Count - 1] = e.Location;
                        polygon.Points.Add(e.Location);
                    }

                    isMouseDown = false;
                }
                else if (currentShape == CurrentShape.Pyramid)
                {
                    if (!isDrawPyramid)
                    {
                        Pyramid pyramid = new Pyramid
                        {
                            LineWidth = cbSize.SelectedIndex,
                            Color     = btnColors.BackColor,
                            DashStyle = DashStyle.Solid
                        };
                        pyramid.Points.Add(e.Location);
                        pyramid.Points.Add(e.Location);

                        shapes.Add(pyramid);

                        isDrawPyramid = true;
                    }
                    else
                    {
                        Pyramid pyramid = shapes[shapes.Count - 1] as Pyramid;
                        pyramid.Points[pyramid.Points.Count - 1] = e.Location;
                        pyramid.Points.Add(e.Location);
                        if (pyramid.Points.Count == 4)
                        {
                            isDrawPyramid = false;
                        }
                    }
                    isMouseDown = false;
                }
                else if (currentShape == CurrentShape.Bezier)
                {
                    if (!isDrawBezier)
                    {
                        Curve bezier = new Curve
                        {
                            LineWidth = cbSize.SelectedIndex,
                            Color     = btnColors.BackColor,
                            DashStyle = DashStyle.Solid
                        };
                        bezier.Points.Add(e.Location);
                        bezier.Points.Add(e.Location);

                        shapes.Add(bezier);

                        isDrawBezier = true;
                    }
                    else
                    {
                        Curve bezier = shapes[shapes.Count - 1] as Curve;
                        if (bezier.Points.Count < 4)
                        {
                            bezier.Points[bezier.Points.Count - 1] = e.Location;
                            bezier.Points.Add(e.Location);
                        }
                        else
                        {
                            isDrawBezier = false;
                            FindCurveRegion(bezier);
                        }
                    }
                    isMouseDown = false;
                }
            }
        }
Пример #4
0
        private void panel_Paint(object sender, PaintEventArgs e)
        {
            brush = new SolidBrush(Color.White);

            if (listColor.SelectedIndex == 0)
            {
                brush.Color = Color.Red;
            }
            else if (listColor.SelectedIndex == 1)
            {
                brush.Color = Color.Green;
            }
            else if (listColor.SelectedIndex == 2)
            {
                brush.Color = Color.Yellow;
            }
            else if (listColor.SelectedIndex == 3)
            {
                brush.Color = Color.Blue;
            }
            else if (listColor.SelectedIndex == 4)
            {
                brush.Color = Color.White;
            }
            else if (listColor.SelectedIndex == 5)
            {
                brush.Color = Color.Black;
            }


            if (listShapes.SelectedIndex == 0)
            {
                RectangleForm form = new RectangleForm();
                form.ShowDialog();

                string width  = form.textBox1.Text;
                string height = form.textBox2.Text;
                if (width != "" && height != "")
                {
                    int width1, height1;
                    if (!Int32.TryParse(width, out width1) || !Int32.TryParse(height, out height1))
                    {
                        MessageBox.Show("Incorrect input data");
                    }
                    else
                    {
                        Point[] point = new Point[4];
                        point[0] = new Point(pointX, pointY);
                        point[1] = new Point(pointX, pointY + height1);
                        point[2] = new Point(pointX + width1, pointY + height1);
                        point[3] = new Point(pointX + width1, pointY);
                        Shapes.Rectangle rectangle = new Shapes.Rectangle(point);

                        rectangle.Name = "Rectangle" + listShape.Count.ToString();
                        listShape.Add(rectangle);

                        rectangle.Color = brush.Color;
                        grap.FillPolygon(new SolidBrush(rectangle.Color), rectangle.ToArray());
                        isSave = false;
                    }
                }
            }
            panel1.BackColor = Color.White;
        }