Beispiel #1
0
 public void DrawLine(ref OxFigure visual, Point point1, Point point2)
 {
     using (var dc = visual.RenderOpen())
     {
         dc.DrawLine(DrawingPen, point1, point2);
     }
 }
Beispiel #2
0
 public MoveCommand(OxFigure value, CanvasLayer curCanv, Point newCoord, Point oldCoord)
 {
     _value    = value;
     CurCanv   = curCanv;
     _newCoord = newCoord;
     _oldCoord = oldCoord;
 }
Beispiel #3
0
 public FillCommand(OxFigure value, Point coord, Color newColor, Color oldColor)
 {
     _value       = value;
     _coord       = coord;
     _newColor    = newColor;
     _oldColor    = oldColor;
     _value.Color = _newColor;
 }
Beispiel #4
0
 private void drawingSurface_MouseLeftButtonUp(object sender, MouseButtonEventArgs e)
 {
     if (DrawingLayer.GetInstance.IsSel)
     {
         OxFigure selectedVisual = DrawingLayer.GetInstance.SelectedVisual;
         DrawingLayer.GetInstance.DrawFigure(ref selectedVisual, DrawingLayer.GetInstance.LastPoint, false);
         DrawingLayer.GetInstance.IsSel = false;
     }
     DrawingLayer.GetInstance.IsClicked  = false;
     DrawingLayer.GetInstance.IsDragging = false;
 }
Beispiel #5
0
 public void ClearSelection()
 {
     if (SelectedVisual.Name != OxFigure.Shape.Line)
     {
         var topLeftCorner = new Point(SelectedVisual.ContentBounds.TopLeft.X + DrawingPen.Thickness / 2,
                                       SelectedVisual.ContentBounds.TopLeft.Y + DrawingPen.Thickness / 2);
         var flag = IsClicked;
         IsClicked = true;
         OxFigure selectedVisual = SelectedVisual;
         DrawFigure(ref selectedVisual, topLeftCorner, false);
         IsClicked = flag;
     }
     SelectedVisual = null;
 }
Beispiel #6
0
        private void drawingSurface_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
        {
            DrawingLayer.GetInstance.IsChanged = true;
            bool     isLin        = false; // for line
            Point    pointClicked = e.GetPosition(drawingSurface);
            OxFigure visual       = null;

            if (SelectionLayer.GetInstance.CurrentTool != Tools.Erase &&
                SelectionLayer.GetInstance.CurrentTool != Tools.Hand && SelectionLayer.GetInstance.CurrentTool != Tools.Fill)
            {
                #region point

                if (SelectionLayer.GetInstance.CurrentTool == Tools.Point)
                {
                    visual = new OxPoint {
                        Name = OxFigure.Shape.Point
                    };
                }

                #endregion

                #region square

                if (SelectionLayer.GetInstance.CurrentTool == Tools.Square) //
                {
                    visual = new OxRectangle {
                        Name = OxFigure.Shape.Square
                    };
                }

                #endregion

                #region ellipse

                if (SelectionLayer.GetInstance.CurrentTool == Tools.Ellipse)
                {
                    visual = new OxCircle {
                        Name = OxFigure.Shape.Ellispe
                    };
                }

                #endregion

                #region line

                if (SelectionLayer.GetInstance.CurrentTool == Tools.Line)
                {
                    visual = new OxLine {
                        Name = OxFigure.Shape.Line
                    };
                    if (DrawingLayer.GetInstance.IsPoint)
                    {
                        DrawingLayer.GetInstance.Point2 = pointClicked;
                        isLin = true;
                    }
                    else
                    {
                        DrawingLayer.GetInstance.Point1 = pointClicked;
                    }
                    DrawingLayer.GetInstance.IsPoint = !DrawingLayer.GetInstance.IsPoint;
                }

                #endregion

                #region rect

                if (SelectionLayer.GetInstance.CurrentTool == Tools.Rectangle)
                {
                    visual = new OxRectangle {
                        Name = OxFigure.Shape.Rectangle
                    };
                }

                #endregion

                if (visual == null)
                {
                    return;
                }

                if (SelectionLayer.GetInstance.CurrentTool == Tools.Line && isLin)
                {
                    DrawingLayer.GetInstance.DrawFigure(ref visual, pointClicked, false);
                    drawingSurface.AddVisual(visual);
                    UndoRedoLayer.GetInstance.Add(new AddElementCommand(visual, this.drawingSurface));
                }
                else if (SelectionLayer.GetInstance.CurrentTool != Tools.Line)
                {
                    DrawingLayer.GetInstance.DrawFigure(ref visual, pointClicked, false);
                    drawingSurface.AddVisual(visual);
                    //здесь добавление
                    UndoRedoLayer.GetInstance.Add(new AddElementCommand(visual, this.drawingSurface));
                }
            }
            else
            {
                #region erase

                if (SelectionLayer.GetInstance.CurrentTool == Tools.Erase)
                {
                    visual = drawingSurface.GetVisual(pointClicked);
                    if (visual != null)
                    {
                        UndoRedoLayer.GetInstance.Add(new RemoveElementCommand(visual, this.drawingSurface));
                        drawingSurface.DeleteVisual(visual);
                    }
                }

                #endregion

                #region hand

                if (SelectionLayer.GetInstance.CurrentTool == Tools.Hand)
                {
                    Point topLeftCorner = new Point();
                    visual = drawingSurface.GetVisual(pointClicked);

                    if (visual != null)
                    {
                        if (visual.Name == OxFigure.Shape.Line)
                        {
                            DrawingLayer.GetInstance.IsClicked = true;
                            DrawingLayer.GetInstance.DrawFigure(ref visual, topLeftCorner, true);

                            DrawingLayer.GetInstance.ClickOffset = topLeftCorner - pointClicked;
                            DrawingLayer.GetInstance.IsDragging  = true;
                            if (DrawingLayer.GetInstance.SelectedVisual != null && DrawingLayer.GetInstance.SelectedVisual != visual)
                            {
                                DrawingLayer.GetInstance.ClearSelection();
                            }
                            DrawingLayer.GetInstance.SelectedVisual = visual;
                            DrawingLayer.GetInstance.LastPoint      = topLeftCorner;
                            DrawingLayer.GetInstance.IsSel          = true;
                        }
                        else
                        {
                            DrawingLayer.GetInstance.IsClicked = true;
                            topLeftCorner.X = visual.ContentBounds.TopLeft.X + DrawingLayer.GetInstance.DrawingPen.Thickness / 2;
                            topLeftCorner.Y = visual.ContentBounds.TopLeft.Y + DrawingLayer.GetInstance.DrawingPen.Thickness / 2;
                            DrawingLayer.GetInstance.DrawFigure(ref visual, topLeftCorner, true);
                            DrawingLayer.GetInstance.ClickOffset = topLeftCorner - pointClicked;
                            DrawingLayer.GetInstance.IsDragging  = true;
                            if (DrawingLayer.GetInstance.SelectedVisual != null && DrawingLayer.GetInstance.SelectedVisual != visual)
                            {
                                DrawingLayer.GetInstance.ClearSelection();
                            }
                            DrawingLayer.GetInstance.SelectedVisual = visual;
                            DrawingLayer.GetInstance.IsSel          = true;
                            DrawingLayer.GetInstance.LastPoint      = topLeftCorner;
                        }
                        UndoRedoLayer.GetInstance.Add(new MoveCommand(DrawingLayer.GetInstance.SelectedVisual, this.drawingSurface, DrawingLayer.GetInstance.LastPoint, pointClicked));
                    }
                    else if (DrawingLayer.GetInstance.IsSel)
                    {
                        OxFigure selectedVisual = DrawingLayer.GetInstance.SelectedVisual;
                        DrawingLayer.GetInstance.DrawFigure(ref selectedVisual, DrawingLayer.GetInstance.LastPoint, false);
                        DrawingLayer.GetInstance.IsSel = false;
                        //UndoRedoLayer.GetInstance.Add(new MoveCommand(selectedVisual, this.drawingSurface, DrawingLayer.GetInstance.LastPoint, topLeftCorner));
                    }
                }

                #endregion

                #region fill

                if (SelectionLayer.GetInstance.CurrentTool == Tools.Fill)
                {
                    visual = drawingSurface.GetVisual(pointClicked);
                    if (visual != null)
                    {
                        DrawingLayer.GetInstance.IsFill = true;
                        Point topLeftCorner = new Point(visual.ContentBounds.TopLeft.X + DrawingLayer.GetInstance.DrawingPen.Thickness / 2,
                                                        visual.ContentBounds.TopLeft.Y + DrawingLayer.GetInstance.DrawingPen.Thickness / 2);
                        UndoRedoLayer.GetInstance.Add(new FillCommand(visual, topLeftCorner, SelectionLayer.GetInstance.CurrentColor, visual.Color));
                        visual.Color = SelectionLayer.GetInstance.CurrentColor;
                        DrawingLayer.GetInstance.IsClicked = true;
                        DrawingLayer.GetInstance.DrawFigure(ref visual, topLeftCorner, false);
                        DrawingLayer.GetInstance.IsClicked = false;
                    }
                    else
                    {
                        DrawingLayer.GetInstance.DrawingBrush =
                            (Brush)DrawingLayer.GetInstance.BrushConverter.ConvertFromString(SelectionLayer.GetInstance.CurrentColor.ToString());
                        drawingSurface.Background = DrawingLayer.GetInstance.DrawingBrush;
                    }
                }

                #endregion
            }
        }
Beispiel #7
0
        public void DrawFigure(ref OxFigure visual, Point topLeftCorner, bool isSelected)
        {
            var curSize = new System.Windows.Size(1, 1);

            //Debug.WriteLine(topLeftCorner.ToString());
            if (ColorChange && IsClicked)
            {
                ColorChange = false;
            }

            DrawingBrush = (Brush)BrushConverter.ConvertFromString(visual.Color.ToString());

            if (IsFill)
            {
                DrawingBrush = (Brush)BrushConverter.ConvertFromString(SelectionLayer.GetInstance.CurrentColor.ToString());
            }

            using (var dc = visual.RenderOpen())
            {
                if (isSelected)
                {
                    DrawingBrush = SelectedDrawingBrush;
                }
                switch (visual.Name)
                {
                case OxFigure.Shape.Point:
                {
                    DrawingBrush = (Brush)BrushConverter.ConvertFromString(Colors.Black.ToString());
                    dc.DrawRoundedRectangle(DrawingBrush, DrawingPen,
                                            new Rect(topLeftCorner, new System.Windows.Size(7, 7)), 5, 5);
                    var oxPoint = visual as OxPoint;
                    if (oxPoint != null)
                    {
                        oxPoint.X = (int)topLeftCorner.X;
                    }
                    if (oxPoint != null)
                    {
                        oxPoint.Y = (int)topLeftCorner.Y;
                    }
                    break;
                }

                case OxFigure.Shape.Square:
                {
                    if (IsClicked)
                    {
                        curSize = visual.size;
                    }
                    else
                    {
                        switch (SelectionLayer.GetInstance.CurrentSize)
                        {
                        case Size.Small:
                            curSize = new System.Windows.Size(40, 40);
                            break;

                        case Size.Medium:
                            curSize = new System.Windows.Size(70, 70);
                            break;

                        case Size.Large:
                            curSize = new System.Windows.Size(110, 110);
                            break;

                        default:
                            curSize = visual.size;
                            break;
                        }
                    }
                    dc.DrawRectangle(DrawingBrush, DrawingPen, new Rect(topLeftCorner, curSize));
                    var oxRect = visual as OxRectangle;
                    if (oxRect != null)
                    {
                        oxRect.X = (int)topLeftCorner.X;
                    }
                    if (oxRect != null)
                    {
                        oxRect.Y = (int)topLeftCorner.Y;
                    }
                    if (oxRect != null)
                    {
                        oxRect.X2 = (int)(topLeftCorner.X + curSize.Height);
                    }
                    if (oxRect != null)
                    {
                        oxRect.Y2 = (int)(topLeftCorner.Y + curSize.Width);
                    }
                    if (oxRect != null)
                    {
                        oxRect.size = curSize;
                    }
                    break;
                }

                case OxFigure.Shape.Ellispe:
                {
                    if (IsClicked)
                    {
                        curSize = visual.size;
                    }
                    else
                    {
                        switch (SelectionLayer.GetInstance.CurrentSize)
                        {
                        case Size.Small:
                            curSize = new System.Windows.Size(40, 40);
                            break;

                        case Size.Medium:
                            curSize = new System.Windows.Size(70, 70);
                            break;

                        case Size.Large:
                            curSize = new System.Windows.Size(110, 110);
                            break;

                        default:
                            curSize = visual.size;
                            break;
                        }
                    }
                    dc.DrawRoundedRectangle(DrawingBrush, DrawingPen, new Rect(topLeftCorner, curSize), 80, 80);
                    var oxCirca = visual as OxCircle;
                    if (oxCirca != null)
                    {
                        oxCirca.X = (int)topLeftCorner.X;
                    }
                    if (oxCirca != null)
                    {
                        oxCirca.Y = (int)topLeftCorner.Y;
                    }
                    if (oxCirca != null)
                    {
                        oxCirca.size = curSize;
                    }
                    if (oxCirca != null)
                    {
                        oxCirca.Radius = (int)(curSize.Height / 2);
                    }
                    break;
                }

                case OxFigure.Shape.Rectangle:
                {
                    if (IsClicked)
                    {
                        curSize = visual.size;
                    }
                    else
                    {
                        switch (SelectionLayer.GetInstance.CurrentSize)
                        {
                        case Size.Small:
                            curSize = new System.Windows.Size(40, 23);
                            break;

                        case Size.Medium:
                            curSize = new System.Windows.Size(80, 45);
                            break;

                        case Size.Large:
                            curSize = new System.Windows.Size(120, 70);
                            break;

                        default:
                            curSize = visual.size;
                            break;
                        }
                    }
                    dc.DrawRectangle(DrawingBrush, DrawingPen, new Rect(topLeftCorner, curSize));
                    var oxRect = visual as OxRectangle;
                    if (oxRect != null)
                    {
                        oxRect.X = (int)topLeftCorner.X;
                    }
                    if (oxRect != null)
                    {
                        oxRect.Y = (int)topLeftCorner.Y;
                    }
                    if (oxRect != null)
                    {
                        oxRect.X2 = (int)(topLeftCorner.X + curSize.Width);
                    }
                    if (oxRect != null)
                    {
                        oxRect.Y2 = (int)(topLeftCorner.Y + curSize.Height);
                    }
                    if (oxRect != null)
                    {
                        oxRect.size = curSize;
                    }
                    break;
                }

                case OxFigure.Shape.Line:
                {
                    if (!IsClicked)
                    {
                        visual.Vect1 = Point1 - topLeftCorner;
                        visual.Vect2 = Point2 - topLeftCorner;
                    }
                    Point1 = new Point(visual.Vect1.X + topLeftCorner.X, visual.Vect1.Y + topLeftCorner.Y);
                    Point2 = new Point(visual.Vect2.X + topLeftCorner.X, visual.Vect2.Y + topLeftCorner.Y);
                    //   drawingPen = new Pen(Brushes.Black, 2)
                    dc.DrawLine(DrawingPen, Point1, Point2);
                    var oxLine = visual as OxLine;
                    if (oxLine != null)
                    {
                        oxLine.X = (int)Point1.X;
                    }
                    if (oxLine != null)
                    {
                        oxLine.Y = (int)Point1.Y;
                    }
                    if (oxLine != null)
                    {
                        oxLine.X2 = (int)Point2.X;
                    }
                    if (oxLine != null)
                    {
                        oxLine.Y2 = (int)Point2.Y;
                    }
                    break;
                }
                }
                visual.size = curSize;
            }
        }