Exemplo n.º 1
0
 public override void ProcessImage(Graphics g)
 {
     if (!disposed)
     {
         BrushDrawing.ChangeGraphicsColor(BrushPoint, g, BrushColor, DrawAtX, DrawAtY);
     }
 }
Exemplo n.º 2
0
 public override void ProcessImage(Graphics g)
 {
     if (!disposed)
     {
         BrushDrawing.ChangeGraphicsColor(PencilPoints, g, PencilColor, DrawAtX, DrawAtY);
     }
 }
Exemplo n.º 3
0
 public override void ProcessImage(Graphics g)
 {
     BrushDrawing.ChangeGraphicsColor(FillPoints, g, FillColor, DrawAtX, DrawAtY);
 }
Exemplo n.º 4
0
        private void canvaspre_Paint(object sender, PaintEventArgs e)
        {
            if (!paintLock)
            {
                paintLock = true;
                //if (!actionLock)
                //    if (!fillLock)
                //        if (!editLock)
                //            try { e.Graphics.DrawImage(endImage, 0, 0); } catch { MessageBox.Show("Canvaspre paint error! Check locks!"); } // The try + catch is only there in case of a case where I haven't checked my locks.

                //try { e.Graphics.DrawImage(canvaspre.Image, 0, 0, canvaspre.Width, canvaspre.Height); } catch { }
                //if (canvaspre.Image != null) canvaspre.Image = null;

                // This is to preview what you are drawing!

                if (MouseDownOnCanvas)
                {
                    if (CurrentDrawingElement is Pencil)
                    {
                        e.Graphics.DrawPath(new Pen(clrNorm.BackColor), Grph);
                    }

                    if (CurrentDrawingElement is Objects.Elements.Brush asBrush)
                    {
                        BrushDrawing.ChangeGraphicsColor(asBrush.BrushPoint, e.Graphics, clrNorm.BackColor);
                    }

                    if (CurrentDrawingElement is RectangleE asRectangle)
                    {
                        // Now let's draw this rectangle!

                        int width  = (MousePoint.X - StartPoint.X);
                        int height = (MousePoint.Y - StartPoint.Y);

                        int heightamount = 0;
                        int widthamount  = 0;
                        if (width < 0)
                        {
                            widthamount = Math.Abs(width);
                        }
                        else
                        {
                            widthamount = 0;
                        }

                        if (height < 0)
                        {
                            heightamount = Math.Abs(height);
                        }
                        else
                        {
                            heightamount = 0;
                        }

                        //if (width < 0) CurrentDrawingElement.Width = 1;
                        //if (height < 0) CurrentDrawingElement.Height = 1;

                        int borderSize = Convert.ToInt32(string.IsNullOrEmpty(txtBWidth.Text) ? "0" : txtBWidth.Text);

                        if (asRectangle.IsFilled)
                        {
                            e.Graphics.FillRectangle(new SolidBrush(asRectangle.FillColor), StartPoint.X - widthamount + (borderSize / 2), StartPoint.Y - heightamount + (borderSize / 2), Math.Abs(width), Math.Abs(height));                       // Fill
                        }
                        e.Graphics.DrawRectangle(new Pen(asRectangle.BorderColor, borderSize), StartPoint.X - widthamount + (borderSize / 2), StartPoint.Y - heightamount + (borderSize / 2), Math.Abs(width), Math.Abs(height));
                        //e.Graphics.FillRectangle(new SolidBrush(ele.borderColor), DrawingMin.X, DrawingMin.Y, ele.BorderSize, height); // Left border
                        //e.Graphics.FillRectangle(new SolidBrush(ele.borderColor), DrawingMin.X, DrawingMin.Y, width, ele.BorderSize); // Top border
                        //e.Graphics.FillRectangle(new SolidBrush(ele.borderColor), (ele.Width - ele.BorderSize) + DrawingMin.X, DrawingMin.Y, ele.BorderSize, Height); // Right border
                        //e.Graphics.FillRectangle(new SolidBrush(ele.borderColor), DrawingMin.X, (ele.Height - ele.BorderSize) + DrawingMin.Y, ele.Width, ele.BorderSize); // Bottom border
                    }

                    if (CurrentDrawingElement is Ellipse asEllipse)
                    {
                        // Now let's draw this ellipse! and yes this is practically the same code as the rectangle one - both of them use the same code for things

                        int width  = (MousePoint.X - StartPoint.X);
                        int height = (MousePoint.Y - StartPoint.Y);

                        int heightamount = 0;
                        int widthamount  = 0;
                        if (width < 0)
                        {
                            widthamount = Math.Abs(width);
                        }
                        else
                        {
                            widthamount = 0;
                        }

                        if (height < 0)
                        {
                            heightamount = Math.Abs(height);
                        }
                        else
                        {
                            heightamount = 0;
                        }

                        //if (width < 0) CurrentDrawingElement.Width = 1;
                        //if (height < 0) CurrentDrawingElement.Height = 1;

                        int borderSize = Convert.ToInt32(string.IsNullOrEmpty(txtBWidth.Text) ? "0" : txtBWidth.Text);
                        if (asEllipse.IsFilled)
                        {
                            e.Graphics.FillEllipse(new SolidBrush(asEllipse.FillColor), StartPoint.X - widthamount + (borderSize / 2), StartPoint.Y - heightamount + (borderSize / 2), Math.Abs(width), Math.Abs(height));                     // Fill
                        }
                        e.Graphics.DrawEllipse(new Pen(asEllipse.BorderColor, borderSize), StartPoint.X - widthamount + (borderSize / 2), StartPoint.Y - heightamount + (borderSize / 2), Math.Abs(width), Math.Abs(height));
                        //e.Graphics.FillRectangle(new SolidBrush(ele.borderColor), DrawingMin.X, DrawingMin.Y, ele.BorderSize, height); // Left border
                        //e.Graphics.FillRectangle(new SolidBrush(ele.borderColor), DrawingMin.X, DrawingMin.Y, width, ele.BorderSize); // Top border
                        //e.Graphics.FillRectangle(new SolidBrush(ele.borderColor), (ele.Width - ele.BorderSize) + DrawingMin.X, DrawingMin.Y, ele.BorderSize, Height); // Right border
                        //e.Graphics.FillRectangle(new SolidBrush(ele.borderColor), DrawingMin.X, (ele.Height - ele.BorderSize) + DrawingMin.Y, ele.Width, ele.BorderSize); // Bottom border
                    }

                    if (CurrentDrawingElement is Line)
                    {
                        int thickness = (txtBThick.Text.Length > 0) ? int.Parse(txtBThick.Text, CultureInfo.CurrentCulture) : 0;
                        e.Graphics.DrawLine(new Pen(clrNorm.BackColor, thickness), StartPoint.X, StartPoint.Y, MousePoint.X, MousePoint.Y);
                    }

                    if (CurrentDrawingElement is Text txt)
                    {
                        e.Graphics.DrawString(txt.MainText, txt.Fnt, new SolidBrush(txt.Clr), MousePoint.X, MousePoint.Y);
                    }
                }

                // ...or to draw the overlay of the selection tool...

                if (SelectedElement != null)
                {
                    int width  = Math.Abs(SelectedElement.Width);
                    int height = Math.Abs(SelectedElement.Height);

                    e.Graphics.DrawRectangle(new Pen(Color.Gray, 3), SelectedElement.X - 1, SelectedElement.Y - 1, width + 1, height + 1);
                    e.Graphics.DrawRectangle(new Pen(Color.Blue), SelectedElement.X - 1, SelectedElement.Y - 1, width + 1, height + 1);

                    // The points for scaling

                    if (IsOnSelection)
                    {
                        if (SelectedElement is Line lineEle)
                        {
                            if (CornerSelected == Corner.TopLeft)
                            {
                                e.Graphics.FillEllipse(new SolidBrush(Color.Gray), lineEle.StartPoint.X + SelectedElement.X - 10, lineEle.StartPoint.Y + SelectedElement.Y - 10, 20, 20);
                            }
                            else
                            {
                                e.Graphics.DrawEllipse(new Pen(Color.Gray), lineEle.StartPoint.X + SelectedElement.X - 10, lineEle.StartPoint.Y + SelectedElement.Y - 10, 20, 20);
                            }
                            if (CornerSelected == Corner.TopRight)
                            {
                                e.Graphics.FillEllipse(new SolidBrush(Color.Gray), lineEle.EndPoint.X + SelectedElement.X - 10, lineEle.EndPoint.Y + SelectedElement.Y - 10, 20, 20);
                            }
                            else
                            {
                                e.Graphics.DrawEllipse(new Pen(Color.Gray), lineEle.EndPoint.X + SelectedElement.X - 10, lineEle.EndPoint.Y + SelectedElement.Y - 10, 20, 20);
                            }
                        }
                        else
                        {
                            if (!(SelectedElement is Pencil) && !(SelectedElement is Objects.Elements.Brush) && !(SelectedElement is Fill))
                            {
                                if (CornerSelected == Corner.TopLeft)
                                {
                                    e.Graphics.FillEllipse(new SolidBrush(Color.Gray), SelectedElement.X - 10, SelectedElement.Y - 10, 20, 20);
                                }
                                else
                                {
                                    e.Graphics.DrawEllipse(new Pen(Color.Gray), SelectedElement.X - 10, SelectedElement.Y - 10, 20, 20);
                                }
                                if (CornerSelected == Corner.TopRight)
                                {
                                    e.Graphics.FillEllipse(new SolidBrush(Color.Gray), ((SelectedElement.X) + SelectedElement.Width) - 10, SelectedElement.Y - 10, 20, 20);
                                }
                                else
                                {
                                    e.Graphics.DrawEllipse(new Pen(Color.Gray), ((SelectedElement.X) + SelectedElement.Width) - 10, SelectedElement.Y - 10, 20, 20);
                                }
                                if (CornerSelected == Corner.BottomLeft)
                                {
                                    e.Graphics.FillEllipse(new SolidBrush(Color.Gray), SelectedElement.X - 10, ((SelectedElement.Y) + SelectedElement.Height) - 10, 20, 20);
                                }
                                else
                                {
                                    e.Graphics.DrawEllipse(new Pen(Color.Gray), SelectedElement.X - 10, ((SelectedElement.Y) + SelectedElement.Height) - 10, 20, 20);
                                }
                                if (CornerSelected == Corner.BottomRight)
                                {
                                    e.Graphics.FillEllipse(new SolidBrush(Color.Gray), ((SelectedElement.X) + SelectedElement.Width) - 10, ((SelectedElement.Y) + SelectedElement.Height) - 10, 20, 20);
                                }
                                else
                                {
                                    e.Graphics.DrawEllipse(new Pen(Color.Gray), ((SelectedElement.X) + SelectedElement.Width) - 10, ((SelectedElement.Y) + SelectedElement.Height) - 10, 20, 20);
                                }
                            }
                        }
                    }
                }

                // ...or even for the drag region overlay...

                if (IsInDragRegion)
                {
                    int heightamount = 0;
                    int widthamount  = 0;
                    if (DragRegionSelect.Width < 0)
                    {
                        widthamount = Math.Abs(DragRegionSelect.Width);
                    }
                    else
                    {
                        widthamount = 0;
                    }

                    if (DragRegionSelect.Height < 0)
                    {
                        heightamount = Math.Abs(DragRegionSelect.Height);
                    }
                    else
                    {
                        heightamount = 0;
                    }

                    e.Graphics.DrawRectangle(new Pen(Color.Gray, 3), DragRegionSelect.X - widthamount, DragRegionSelect.Y - heightamount, Math.Abs(DragRegionSelect.Width) + 1, Math.Abs(DragRegionSelect.Height) + 1);
                    e.Graphics.DrawRectangle(new Pen(Color.Green), DragRegionSelect.X - widthamount, DragRegionSelect.Y - heightamount, Math.Abs(DragRegionSelect.Width) + 1, Math.Abs(DragRegionSelect.Height) + 1);
                }

                // ...or for just drawing the element that's moving.

                if (RedrawSelectedElementOnly && SelectedElement != null && BeforeMove != null)
                {
                    e.Graphics.DrawImage(BeforeMove, 0, 0);
                    SelectedElement.ProcessImage(e.Graphics);
                }

                paintLock = false;
            }
        }