Exemplo n.º 1
0
        private void panelResizeSheet_MouseUp(object sender, MouseEventArgs e)
        {
            if (cursorActive == true)
            {
                var jsonSerializerSettings = new JsonSerializerSettings()
                {
                    TypeNameHandling = TypeNameHandling.All
                };
                VectorCanvas tmp  = VectorCanvas.GetCanvas;
                string       file = "";
                foreach (Drawfigure f in tmp.figures)
                {
                    string json = JsonConvert.SerializeObject(f, jsonSerializerSettings);
                    file += json + "|";
                }

                pictureBoxSheet.Size += (Size)e.Location;
                pictureBoxSheet.DrawToBitmap(Canvas.GetCanvas.Bmp.Bmp, pictureBoxSheet.ClientRectangle);
                VectorCanvas.GetCanvas.Init(pictureBoxSheet.Width, pictureBoxSheet.Height);

                string[] lines = file.Split(new string[] { "|" }, StringSplitOptions.RemoveEmptyEntries);
                for (int i = 0; i < lines.Length; i++)
                {
                    Drawfigure f = JsonConvert.DeserializeObject <Drawfigure>(lines[i], jsonSerializerSettings);
                    tmp.figures.Add(f);
                }
                VectorCanvas.GetCanvas.RenderWrite(pictureBoxSheet);

                cleanMemory();
            }
        }
Exemplo n.º 2
0
 public void MouseMove(PictureBox sheet, IBrush brush, IFill fill, MouseEventArgs e)
 {
     figure.Create(x1, y1, x2, y2);
     figureTmp.Create(x1, y1, x2, y2);
     if (cursorActive == true)
     {
         canvas.LoadFromCache();
         x2 = e.X;
         y2 = e.Y;
         IFill  tmpFill = new NoFill();
         IBrush tmpBrush;
         if (fill is OnlyFill)
         {
             tmpBrush = new SquareBrush(1, fill.FillColor);
         }
         else
         {
             tmpBrush = brush;
         }
         Drawfigure drawer    = new Drawfigure(figure, tmpBrush, tmpFill);
         Drawfigure drawerTmp = new Drawfigure(figureTmp, tmpBrush, tmpFill);
         drawer.Draw(canvas);
         canvas.WriteToPictureBox(sheet);
     }
 }
Exemplo n.º 3
0
        public void PointChangeModeOfRectangle(PictureBox sheet, Drawfigure obj)
        {
            SquareBrush  brush         = new SquareBrush(1, Color.Blue);
            Square       square        = new Square();
            List <Point> rectanglelist = new List <Point>();

            rectanglelist.Add(obj.figure.cornerTopLeft);
            rectanglelist.Add(obj.figure.cornerBottomRight);
            rectanglelist.Add(obj.figure.cornerBottomLeft);
            rectanglelist.Add(obj.figure.cornerTopRight);


            foreach (Point t in rectanglelist)
            {
                for (int i = -3; i <= 3; i++)
                {
                    Point p1 = new Point(t.X - 3, t.Y + i);
                    Point p2 = new Point(t.X + 3, t.Y + i);
                    square.Createdotlist(p1.X, p1.Y, p2.X, p2.Y);
                    //WriteToPictureBox(sheet);
                    brush.DrawLine(Bmp, p1.X, p1.Y, p2.X, p2.Y, false);
                    WriteToPictureBox(sheet);
                }
            }
        }
Exemplo n.º 4
0
 public VectorRepaintTool()
 {
     cursorActive = false;
     canvas       = VectorCanvas.GetCanvas;
     activeFigure = null;
     //this.figure = (IFigure)figure.Clone();
     //this.brush = (IBrush)brush.Clone();
     //this.fill = (IFill)fill.Clone();
 }
Exemplo n.º 5
0
 public void RenderExceptFigure(Drawfigure df)
 {
     Bmp = new BitmapWrap(Width, Height);
     foreach (Drawfigure f in figures)
     {
         if (df != f)
         {
             f.Draw(this);
         }
     }
 }
 public void MouseDown(PictureBox sheet, IBrush brush, IFill fill, MouseEventArgs e)
 {
     foreach (Drawfigure f in canvas.figures)
     {
         if (f.figure.IsInside(e.Location))
         {
             activeFigure = f;
             cursorActive = true;
             canvas.RenderExceptFigure(activeFigure);
             canvas.SaveToCache();
         }
     }
 }
Exemplo n.º 7
0
        private void OpenToolStripMenuItem_Click(object sender, EventArgs e) // Открыть файл
        {
            if (canvas == Canvas.GetCanvas)
            {
                string filePath;

                openFileDialog.InitialDirectory = "c:\\";
                openFileDialog.Filter           = " All files (*.*)|*.*| Portable net graphics (*.png)|*.png| Bitmap files (*.bmp)|*.bmp";
                openFileDialog.FilterIndex      = 2;
                openFileDialog.RestoreDirectory = true;

                if (openFileDialog.ShowDialog() == DialogResult.OK)
                {
                    filePath = openFileDialog.FileName;
                    pictureBoxSheet.Load(filePath + "");
                    startProgram();
                    pictureBoxSheet.DrawToBitmap(Canvas.GetCanvas.Bmp.Bmp, pictureBoxSheet.ClientRectangle);
                }
            }

            if (canvas == VectorCanvas.GetCanvas)
            {
                string[] fileContent;
                string   filePath;

                openFileDialog.InitialDirectory = "c:\\";
                saveFileDialog.Filter           = " JSON (*.json)|*.json";
                openFileDialog.FilterIndex      = 0;
                openFileDialog.RestoreDirectory = true;
                var jsonSerializerSettings = new JsonSerializerSettings()
                {
                    TypeNameHandling = TypeNameHandling.All
                };

                if (openFileDialog.ShowDialog() == DialogResult.OK)
                {
                    filePath    = openFileDialog.FileName;
                    fileContent = File.ReadAllLines(filePath);
                    VectorCanvas tmp = VectorCanvas.GetCanvas;
                    tmp.figures.Clear();
                    for (int i = 0; i < fileContent.Length; i++)
                    {
                        Drawfigure f = JsonConvert.DeserializeObject <Drawfigure>(fileContent[i], jsonSerializerSettings);
                        tmp.figures.Add(f);
                    }
                    VectorCanvas.GetCanvas.RenderWrite(pictureBoxSheet);
                }
            }
        }
Exemplo n.º 8
0
        public void MouseUp(PictureBox sheet, IBrush brush, IFill fill, MouseEventArgs e)
        {
            cursorActive = false;
            x2           = e.X;
            y2           = e.Y;
            Drawfigure drawer    = new Drawfigure(figure, brush, fill);
            Drawfigure drawerTmp = new Drawfigure(figureTmp, brush, fill);

            if (canvas is VectorCanvas)
            {
                VectorCanvas.GetCanvas.figures.Add(drawer);
                VectorCanvas.GetCanvas.figuresTmp.Add(drawerTmp);
            }
            drawer.Draw(canvas);
            canvas.WriteToPictureBox(sheet);
        }
        public void MouseDown(PictureBox sheet, IBrush brush, IFill fill, MouseEventArgs e)
        {
            cursorActive = true;
            for (int i = -10; i <= 10; i++)
            {
                for (int j = -10; j <= 10; j++)
                {
                    Point p = new Point(e.X + i, e.Y + j);
                    activeFigure = canvas.FindFigureByPoint(p);
                    if (activeFigure != null)
                    {
                        tmpIndex = canvas.FindPointByPoint(p);
                        break;
                    }
                }
                if (activeFigure != null)
                {
                    break;
                }
            }

            //для дабл клика(добавления вершин)
            if (activeFigure == null)
            {
                cursorActive = false;
                foreach (Drawfigure f in canvas.figures)
                {
                    if (f.figure.IsInside(e.Location))
                    {
                        activeFigure = f;
                    }
                }
            }
            //---------
            if (activeFigure != null)
            {
                canvas.RenderExceptFigure(activeFigure);
                canvas.SaveToCache();
                activeFigure.Draw(canvas);
                canvas.WriteToPictureBox(sheet);
            }
        }
Exemplo n.º 10
0
 public void MouseDown(PictureBox sheet, IBrush brush, IFill fill, MouseEventArgs e)
 {
     foreach (Drawfigure f in canvas.figures)
     {
         if (f.figure.IsInside(e.Location))
         {
             activeFigure    = f;
             index           = canvas.figures.IndexOf(activeFigure);
             activeFigureTmp = canvas.figuresTmp[index];
             for (int i = 0; i < activeFigureTmp.figure.dotlist.Count; i++)
             {
                 activeFigure.figure.dotlist[i] = activeFigureTmp.figure.dotlist[i];
             }
             activeFigure.brush = activeFigureTmp.brush;
             activeFigure.fill  = activeFigureTmp.fill;
             cursorActive       = true;
             canvas.SaveToCache();
         }
     }
 }
Exemplo n.º 11
0
        public void MouseClick(PictureBox sheet, IBrush brush, IFill fill, MouseEventArgs e)
        {
            foreach (Drawfigure f in canvas.figures)
            {
                if (f.figure.IsInside(e.Location))
                {
                    activeFigure = f;

                    cursorActive = true;
                    canvas.RenderExceptFigure(activeFigure);
                    canvas.SaveToCache();
                }
            }

            if (activeFigure != null)
            {
                activeFigure.figure.ChangeCorners();
                canvas.PointChangeModeOfRectangle(sheet, activeFigure);
                havecorners = true;
            }
        }
Exemplo n.º 12
0
        public void PointChangeModeActiveFigure(PictureBox sheet, Drawfigure obj)
        {
            SquareBrush brush  = new SquareBrush(1, Color.Red);
            Square      square = new Square();

            if (obj.figure is Ellips || obj.figure is Circle)
            {
                brush.BrushColor = obj.brush.BrushColor;
                brush.BrushSize  = 0;
            }
            foreach (Point t in obj.figure.dotlist)
            {
                for (int i = -3; i <= 3; i++)
                {
                    Point p1 = new Point(t.X - 3, t.Y + i);
                    Point p2 = new Point(t.X + 3, t.Y + i);
                    square.Createdotlist(p1.X, p1.Y, p2.X, p2.Y);
                    brush.DrawLine(Bmp, p1.X, p1.Y, p2.X, p2.Y, false);
                    WriteToPictureBox(sheet);
                }
            }
        }
Exemplo n.º 13
0
 public VectorFigureOriginalStateTool()
 {
     cursorActive = false;
     canvas       = VectorCanvas.GetCanvas;
     activeFigure = null;
 }
Exemplo n.º 14
0
        // Point farthest;

        public VectorFigureChangeSizeTool()
        {
            cursorActive = false;
            canvas       = VectorCanvas.GetCanvas;
            activeFigure = null;
        }
Exemplo n.º 15
0
 public VectorFigureTurnTool()
 {
     cursorActive = false;
     canvas       = VectorCanvas.GetCanvas;
     activeFigure = null;
 }