Esempio n. 1
0
 public override object Clone()
 {
     MyEllipse clone = new MyEllipse(this.BeginPoint, this.EndPoint);
     clone.Pen = (Pen)this.Pen.Clone();
     clone.Brush = (Brush)this.Brush.Clone();
     clone.IsFill = this.IsFill;
     return clone;
 }
Esempio n. 2
0
        public override object Clone()
        {
            MyEllipse clone = new MyEllipse(this.BeginPoint, this.EndPoint);

            clone.Pen    = (Pen)this.Pen.Clone();
            clone.Brush  = (Brush)this.Brush.Clone();
            clone.IsFill = this.IsFill;
            return(clone);
        }
Esempio n. 3
0
        private void pictureBox1_MouseDown(object sender, MouseEventArgs e)
        {
            if (e.Button == MouseButtons.Right)
            {
                ResetSelect();
            }

            if (e.Button == MouseButtons.Left)
            {
                startMousePoint = e.Location;



                switch (tools)
                {
                case Tools.Fill:
                    for (int i = collection.shapes.Count - 1; i >= 0; i--)
                    {
                        if (collection.shapes[i].Touch(currentPoint))
                        {
                            collection.shapes[i].FillColor = color;
                            break;
                        }
                    }
                    collection.Redraw(graphics);
                    pictureBox1.Image = picture;
                    break;


                case Tools.Select:
                    for (int i = collection.shapes.Count - 1; i >= 0; i--)
                    {
                        bool alreadySelect = false;
                        foreach (int index in collection.indexesOfSelectedShapes)
                        {
                            if (index == i)
                            {
                                alreadySelect = true;
                                break;
                            }
                        }
                        bool touched = collection.shapes[i].Touch(currentPoint);
                        if (!alreadySelect)
                        {
                            if (touched)
                            {
                                collection.indexesOfSelectedShapes.Add(i);
                                collection.Redraw(graphics);
                                pictureBox1.Image = picture;
                            }
                        }
                        else
                        {
                            if (touched)
                            {
                                moveIndex       = i;
                                threadForSelect = new Thread(() =>
                                {
                                    while (moveIndex != -1)
                                    {
                                        collection.shapes[moveIndex].Move(new PointF(startMousePoint.X - currentPoint.X,
                                                                                     startMousePoint.Y - currentPoint.Y));
                                        startMousePoint = currentPoint;
                                        collection.Redraw(graphics);
                                        pictureBox1.Image = picture;
                                        Thread.Sleep(16);
                                    }
                                });
                                threadForSelect.Start();
                                break;
                            }
                        }
                    }
                    break;

                default:
                    threadShapeIsRunning = true;
                    collection.AddShape(new Pryamougolnik(currentPoint, currentPoint, Color.Black, 5));
                    threadShape = new Thread(() =>
                    {
                        while (threadShapeIsRunning)
                        {
                            PointF startPoint = new PointF();
                            PointF endPoint   = new PointF();
                            collection.DeleteLastShape();
                            startPoint.X = Math.Min(startMousePoint.X, currentPoint.X);
                            startPoint.Y = Math.Min(startMousePoint.Y, currentPoint.Y);
                            endPoint.X   = startPoint.X + Math.Abs(currentPoint.X - startMousePoint.X);
                            endPoint.Y   = startPoint.Y + Math.Abs(currentPoint.Y - startMousePoint.Y);
                            switch (tools)
                            {
                            case Tools.Pryamougolnik:
                                Pryamougolnik pryamougolnik = new Pryamougolnik(startPoint, endPoint, color, borderSize);
                                collection.AddShape(pryamougolnik);
                                break;

                            case Tools.MyEllipse:
                                MyEllipse myEllipse = new MyEllipse(startPoint, endPoint, color, borderSize);
                                collection.AddShape(myEllipse);
                                break;

                            case Tools.Triangle:
                                Triangle triangle = new Triangle(startPoint, endPoint, color, borderSize);
                                collection.AddShape(triangle);
                                break;
                            }
                            collection.Redraw(graphics);
                            pictureBox1.Image = picture;
                            Thread.Sleep(16);
                        }
                    }
                                             );
                    threadShape.Start();
                    break;
                }
            }
        }
Esempio n. 4
0
        private void CreateEditBoxShapes(IShape s)
        {
            this.editBoxShapes.Clear();

            int size = 4;                           //размер якоря
            int radius = 15;                        //радиус для круга заливки

            //Инструменты рисования якорей

            Pen smPen = new Pen(Color.Black);
            Brush smBrush = Brushes.LightGreen;

            //Инструменты рисования рамки

            Pen pen = new Pen(Color.Black, 2);
            pen.DashStyle = DashStyle.Dash;

            if (s is Shape)
            {
                Shape shape = s as Shape;

                //Точки по углам

                Point LeftTop = shape.BeginPoint;
                Point RightTop = new Point(shape.EndPoint.X, shape.BeginPoint.Y);
                Point LeftBottom = new Point(shape.BeginPoint.X, shape.EndPoint.Y);
                Point RightBottom = shape.EndPoint;

                //Точки в серединах рёбер

                Point MiddleTop = new Point((LeftTop.X + RightTop.X) / 2, LeftTop.Y);
                Point MiddleBottom = new Point((LeftBottom.X + RightBottom.X) / 2, LeftBottom.Y);
                Point MiddleLeft = new Point(LeftTop.X, (LeftTop.Y + LeftBottom.Y) / 2);
                Point MiddleRight = new Point(RightTop.X, (RightTop.Y + RightBottom.Y) / 2);

                //Центральная точка

                Point Center = new Point(MiddleTop.X, MiddleRight.Y);

                //Основная рамка(Пунктир)

                MyRectangle editRect = new MyRectangle(LeftTop, RightBottom);
                editRect.Pen = pen;
                this.editBoxShapes.Add(editRect);

                //Якоря по углам и середине (чёрная рамка, заливка)

                //Массив точек

                Point[] editPoints = { LeftTop, MiddleTop, RightTop, MiddleLeft, Center, MiddleRight, LeftBottom, MiddleBottom, RightBottom };

                MyRectangle smallEditRect = null;

                foreach (Point point in editPoints)
                {
                    smallEditRect = new MyRectangle(new Point(point.X - size, point.Y - size), new Point(point.X + size, point.Y + size), true);
                    smallEditRect.Pen = smPen;
                    smallEditRect.Brush = smBrush;
                    this.editBoxShapes.Add(smallEditRect);
                }
            }

            // Заливка

            else if (s is MyFill)
            {
                MyFill fill = s as MyFill;

                //Основная окружность(Пунктир)

                MyEllipse editCircle = new MyEllipse(new Point(fill.FillPoint.X - radius, fill.FillPoint.Y - radius), new Point(fill.FillPoint.X + radius, fill.FillPoint.Y + radius));
                editCircle.Pen = pen;
                this.editBoxShapes.Add(editCircle);

                //Центральный прямоугольник

                MyRectangle smallEditRect = new MyRectangle(new Point(fill.FillPoint.X - size, fill.FillPoint.Y - size), new Point(fill.FillPoint.X + size, fill.FillPoint.Y + size), true);
                smallEditRect.Pen = smPen;
                smallEditRect.Brush = smBrush;
                this.editBoxShapes.Add(smallEditRect);
            }

            //Карандаш

            else if (s is MyPen)
            {
                MyPen myPen = s as MyPen;

                //Крайние координаты

                int xMin = this.canvas.Width;
                int xMax = 0;
                int yMin = this.canvas.Height;
                int yMax = 0;

                foreach (Point point in myPen.Points)
                {
                    if (xMin > point.X)
                    {
                        xMin = point.X;
                    }
                    if (xMax < point.X)
                    {
                        xMax = point.X;
                    }
                    if (yMin > point.Y)
                    {
                        yMin = point.Y;
                    }
                    if (yMax < point.Y)
                    {
                        yMax = point.Y;
                    }
                }

                MyRectangle editRect = new MyRectangle(new Point(xMin, yMin), new Point(xMax, yMax));
                editRect.Pen = pen;
                this.editBoxShapes.Add(editRect);

                //Центральный прямоугольник

                int xCenter = (xMin + xMax) / 2;
                int yCenter = (yMin + yMax) / 2;

                MyRectangle smallEditRect = new MyRectangle(new Point(xCenter - size, yCenter - size), new Point(xCenter + size, yCenter + size), true);
                smallEditRect.Pen = smPen;
                smallEditRect.Brush = smBrush;
                this.editBoxShapes.Add(smallEditRect);
            }
        }
Esempio n. 5
0
        private void AddShapeToList(Point endPoint)
        {
            //Обрабатываются в клике

            if (this.typeTool == SHAPES.FILLTOOL || this.typeTool == SHAPES.COLORCHOICE)
            {
                return;
            }

            Shape currentShape = null;
            switch (this.typeTool)
            {
                case SHAPES.PEN:
                    this.pointsOfMovement.Add(endPoint);
                    MyPen myPen = new MyPen(this.pointsOfMovement);
                    Pen pen = new Pen(this.colorChoicer.FColor, this.widthChiocer.LineWidth);
                    myPen.Pen = pen;
                    this.shapesList.Add(myPen);
                    this.pointsOfMovement.Clear();
                    this.UpdateShapeListComboBox();
                    return;
                case SHAPES.LINE:
                    currentShape = new MyLine(this.bPoint, endPoint);
                    break;
                case SHAPES.RECTANGLE:
                    currentShape = new MyRectangle(this.bPoint, endPoint);
                    break;
                case SHAPES.FILLRECTANGLE:
                    currentShape = new MyRectangle(this.bPoint, endPoint, true);
                    break;
                case SHAPES.ELLIPS:
                    currentShape = new MyEllipse(this.bPoint, endPoint);
                    break;
                case SHAPES.FILLELLIPS:
                    currentShape = new MyEllipse(this.bPoint, endPoint, true);
                    break;
                default:
                    throw new ShapeException("Неизвестный тип фигуры");
            }

            Pen currentPen = new Pen(this.colorChoicer.FColor, this.widthChiocer.LineWidth);
            currentPen.DashStyle = this.lineStyleChoicer.SelectedStyle;
            currentShape.Pen = currentPen;

            if (this.hatchChoiser.SelectedHatch == null)
            {
                currentShape.Brush = new SolidBrush(this.colorChoicer.BColor);
            }
            else
            {
                currentShape.Brush = new HatchBrush((HatchStyle)this.hatchChoiser.SelectedHatch, this.colorChoicer.FColor, this.colorChoicer.BColor);
            }

            this.shapesList.Add(currentShape);

            this.UpdateShapeListComboBox();

            this.pointsOfMovement.Clear();
        }