예제 #1
0
        } // Save

        public void Load(string fileName)
        {
            Clear();
            XmlReader reader;

            reader = XmlReader.Create(fileName);

            while (reader.Read())
            {
                if (reader.HasAttributes)
                {
                    if (reader.Name == "Figures")
                    {
                        reader.MoveToFirstAttribute();
                        borderWidth = int.Parse(reader.Value);

                        reader.MoveToNextAttribute();
                        borderHeight = int.Parse(reader.Value);
                    } // if
                    if (reader.Name == "MyPencil")
                    {
                        Add(MyPencil.ReadData(reader));
                    } // if
                    if (reader.Name == "MyRectangle")
                    {
                        Add(MyRectangle.ReadData(reader));
                    } // if
                    if (reader.Name == "MyCircle")
                    {
                        Add(MyCircle.ReadData(reader));
                    } // if
                }
            }         // while
            reader.Close();
        }             // Load
예제 #2
0
        public override object CreateShape(PaintSpace p)
        {
            MyRectangle rect = new MyRectangle(p, pointStart, pointEnd);

            //rect.Draw(p.MainGraphics);
            return(rect);
        }
예제 #3
0
        public override object Clone()
        {
            MyRectangle clone = new MyRectangle(this.BeginPoint, this.EndPoint);

            clone.Pen    = (Pen)this.Pen.Clone();
            clone.Brush  = (Brush)this.Brush.Clone();
            clone.IsFill = this.IsFill;
            return(clone);
        }
예제 #4
0
        public override object CreateShape(PaintSpace p)
        {
            PaintSpace np = new PaintSpace
            {
                BackColor    = Color.Transparent,
                ForeColor    = Color.Transparent,
                MainGraphics = p.MainGraphics,
                DashStyle    = (int)DashStyle.Solid,
                BorderWidth  = 0.5f
            };

            MyRectangle rect = new MyRectangle(np, pointStart, pointEnd);

            return(rect);
        }
예제 #5
0
파일: Paint.cs 프로젝트: HongHanh2104/Paint
        private void mainDrawingPicture_MouseMove(object sender, MouseEventArgs e)
        {
            lb_Mouse.Text = String.Format("Mouse Position: X: {0}; Y: {1}", e.X, e.Y);

            if (e.Button == MouseButtons.Left && currentTool != null)
            {
                if (currentTool.Type() == PaintTool.TransformationTool)
                {
                    Transformation currentShape = currentTool.onMouseMove(e, paintParams) as Transformation;
                    if (listView_layer.SelectedItems.Count > 0)
                    {
                        Layer layer = listView_layer.SelectedItems[0].Tag as Layer;
                        layer.Transform(currentShape);
                        ReDraw();
                        layer.ResetMatrix();
                    }
                }
                else if (currentTool.Type() == PaintTool.CDShapeTool)
                {
                    Shape      currentShape = currentTool.onMouseMove(e, paintParams) as Shape;
                    ShapeLayer layer        = listView_layer.SelectedItems[0].Tag as ShapeLayer;
                    layer.setShape(currentShape);
                    ReDraw();
                }
                else if (currentTool.Type() == PaintTool.SelectionTool)
                {
                    ShowVisibleLayers();

                    MyRectangle  currentShape = currentTool.onMouseMove(e, paintParams) as MyRectangle;
                    GraphicsPath path         = currentShape.GetPath();

                    Pen     pen       = new Pen(Color.Black, 0.1f);
                    float[] dashStyle = new float[] { 2, 5, 10, 4 };
                    pen.DashPattern = dashStyle;

                    mainDrawingGraphics.DrawPath(pen, path);
                    mainDrawingPicture.Refresh();
                }
            }
        }
예제 #6
0
        private void pictureBox1_MouseUp(object sender, MouseEventArgs e)
        {
            isMousePressed = false;
            IShape shape;

            switch (curTool)
            {
            case Tool.Pen:
                break;

            case Tool.Line:
                shape = new MyLine(prevPoint, curPoint, pen);
                shapes.Add(shape);
                break;

            case Tool.Circle:
                shape = new MyCircle(prevPoint, curPoint, pen);
                shapes.Add(shape);
                break;

            case Tool.Rectangle:
                shape = new MyRectangle(prevPoint, curPoint, pen);
                shapes.Add(shape);
                break;

            case Tool.Triangle:
                shape = new MyTriangle(prevPoint, curPoint, pen);
                shapes.Add(shape);
                break;

            case Tool.Select:
                ShapesApplyNewPosition();
                break;

            default:
                break;
            }
            prevPoint = e.Location;
        }
예제 #7
0
파일: MainForm.cs 프로젝트: Dr1N/PaintNET
        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);
            }
        }
예제 #8
0
파일: MainForm.cs 프로젝트: Dr1N/PaintNET
        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();
        }
예제 #9
0
파일: Shape.cs 프로젝트: Dr1N/PaintNET
 public override object Clone()
 {
     MyRectangle clone = new MyRectangle(this.BeginPoint, this.EndPoint);
     clone.Pen = (Pen)this.Pen.Clone();
     clone.Brush = (Brush)this.Brush.Clone();
     clone.IsFill = this.IsFill;
     return clone;
 }