private List <FigureLine> GetListOfLines(List <Control> controls)
        {
            List <FigureLine> lines = new List <FigureLine>();

            foreach (var item in controls)
            {
                if (item.GetType() == typeof(SimpleFigures))
                {
                    using (SimpleFigures sf = (SimpleFigures)item)
                    {
                        if (sf.Type == ShapeType.LINE)
                        {
                            FigureLine l = new FigureLine();
                            l.X         = item.Left;
                            l.Y         = item.Top;
                            l.Width     = item.Width;
                            l.Height    = item.Height;
                            l.PenWidth  = sf.PenWidth;
                            l.Color     = sf.Color;
                            l.ShapeType = ShapeType.LINE;
                            lines.Add(l);
                        }
                    }
                }
            }

            return(lines);
        }
        protected List <FigureEllipse> GetListOfEllipses(List <Control> controls)
        {
            List <FigureEllipse> ellipses = new List <FigureEllipse>();

            foreach (var item in controls)
            {
                if (item.GetType() == typeof(SimpleFigures))
                {
                    using (SimpleFigures sf = (SimpleFigures)item)
                    {
                        if (sf.Type == ShapeType.ELLIPSE)
                        {
                            FigureEllipse l = new FigureEllipse();
                            l.X         = item.Left;
                            l.Y         = item.Top;
                            l.Width     = item.Width;
                            l.Height    = item.Height;
                            l.PenWidth  = sf.PenWidth;
                            l.Color     = sf.Color;
                            l.ShapeType = ShapeType.ELLIPSE;
                            ellipses.Add(l);
                        }
                    }
                }
            }

            return(ellipses);
        }
        protected List <FigureRectangle> GetListOfRects(List <Control> controls)
        {
            List <FigureRectangle> rects = new List <FigureRectangle>();

            foreach (var item in controls)
            {
                if (item.GetType() == typeof(SimpleFigures))
                {
                    using (SimpleFigures sf = (SimpleFigures)item)
                    {
                        if (sf.Type == ShapeType.RECTANGLE)
                        {
                            FigureRectangle l = new FigureRectangle();
                            l.X         = item.Left;
                            l.Y         = item.Top;
                            l.Width     = item.Width;
                            l.Height    = item.Height;
                            l.PenWidth  = sf.PenWidth;
                            l.Color     = sf.Color;
                            l.ShapeType = ShapeType.RECTANGLE;
                            rects.Add(l);
                        }
                    }
                }
            }

            return(rects);
        }
        private void canvas_MouseUp(object sender, MouseButtonEventArgs e)
        {
            if (StackControl == null && e.ChangedButton == MouseButton.Left && e.LeftButton == MouseButtonState.Released)
            {
                isDrawing = false;

                SimpleFigures ctrl = (SimpleFigures)DrawingVector2DTool.Render(this,
                                                                               new Thickness(data.PrevPoint.X, data.PrevPoint.Y,
                                                                                             e.GetPosition(canvas).X, e.GetPosition(canvas).Y),
                                                                               (XData)data.Clone(), cmd
                                                                               );

                ctrl.GainFocus   += this.OnGainFocus;
                ctrl.LostFocus   += this.OnLostFocus;
                ctrl.FigurePaste += this.OnFigurePaste;

                ctrl.ContextMenu_Color.Click     += new RoutedEventHandler(cmd.aColor.Action);
                ctrl.ContextMenu_PenWidth.Click  += new RoutedEventHandler(cmd.aWidth.Action);
                ctrl.ContextMenu_ShapeType.Click += new RoutedEventHandler(cmd.aType.Action);

                data.AddPosition(e.GetPosition(canvas));
                if (data.Type == ShapeType.MULTILINE)
                {
                    Line[] lines = this.canvas.Children.OfType <Line>().ToArray();
                    foreach (var item in lines)
                    {
                        this.canvas.Children.Remove(item);
                    }
                    data.Path = new List <Point>();
                }
            }
        }
        private void Canvas_MouseUp(object sender, MouseEventArgs e)
        {
            if (e.Button == MouseButtons.Left)
            {
                isDrawing = false;

                SimpleFigures ctrl = (SimpleFigures)DrawingVector2DTool.Render(this,
                                                                               new Rectangle(data.PrevPoint, new Size(e.X - data.PrevPoint.X, e.Y - data.PrevPoint.Y)), (XData)data.Clone(), cmd);
                ctrl.GainFocus   += this.OnGainFocus;
                ctrl.LostFocus   += this.OnLostFocus;
                ctrl.FigurePaste += this.OnFigurePaste;
                this.Controls[Controls.Count - 1].BringToFront();

                ctrl.ContextMenu_Color.Click     += new EventHandler(cmd.aColor.Action);
                ctrl.ContextMenu_PenWidth.Click  += new EventHandler(cmd.aWidth.Action);
                ctrl.ContextMenu_ShapeType.Click += new EventHandler(cmd.aType.Action);
                ctrl.PropertyPanel = (this.Parent.Parent.Parent.Parent as MiniPaintV).propertyPanel;

                data.AddPosition(e.Location);
                if (data.Type == ShapeType.MULTILINE)
                {
                    g.Clear(this.BackColor);
                    data.Path = new List <PointF>();
                }
            }
        }
Example #6
0
        public override void Action(object sender, EventArgs e)
        {
            try
            {
                OpenFileDialog openFD = new OpenFileDialog();
                openFD.Filter = "JSON (*.json)|*.json|CSV (*.csv)|*.csv|XML (*.xml)|*.xml|YML (*.yml)|*.yml";
                DialogResult res = openFD.ShowDialog();

                if (res == DialogResult.OK)
                {
                    // TODO: Load file
                    IFigureIO f = FigureIO_Selector.GetInstance(openFD.FileName.Remove(0, openFD.FileName.LastIndexOf('.') + 1));
                    fileName     = openFD.FileName;
                    f.PathToFile = openFD.FileName;
                    cmd.canvas.Controls.AddRange(f.Read().ToArray());
                }
                openFD.Dispose();

                DrawingVector2DTool.figures = new List <Control>();
                for (int i = 1; i < cmd.canvas.Controls.Count; ++i)
                {
                    SimpleFigures f = cmd.canvas.Controls[i] as SimpleFigures;
                    f.GainFocus   += cmd.canvas.OnGainFocus;
                    f.LostFocus   += cmd.canvas.OnLostFocus;
                    f.FigurePaste += cmd.canvas.OnFigurePaste;

                    DrawingVector2DTool.figures.Add(cmd.canvas.Controls[i]);
                    cmd.canvas.Controls[i].BringToFront();

                    f.PropertyPanel = (cmd.canvas.Parent.Parent.Parent.Parent as MiniPaintV).propertyPanel;
                }
            }
            catch { }
        }
        public void OnGainFocus(object sender, EventArgs e)
        {
            SimpleFigures obj = sender as SimpleFigures;

            OnLostFocus(StackControl, null);
            StackControl = obj;
            StackControl.Focus();
        }
        public static Control Render(Control ownerControl, Rectangle rect, XData data, XCommand cmd)
        {
            SimpleFigures result = new SimpleFigures(rect, data);

            result.ContextMenuSetUp(cmd);
            ownerControl.Controls.Add(result);
            figures.Add(result);

            return(result);
        }
Example #9
0
 public FigureResize(SimpleFigures ownerControl, ResizeLocation location)
 {
     InitializeComponent();
     this.ownerControl = ownerControl;
     this.ownerControl.Controls.Add(this);
     this.ownerControl.Controls[this.ownerControl.Controls.Count - 1].BringToFront();
     this.location = location;
     this.Size     = new Size(20, 20);
     PositionSetUp();
 }
Example #10
0
        public static UIElement Render(CanvasVector ownerControl, Thickness rect, XData data, XCommand cmd)
        {
            SimpleFigures result = new SimpleFigures(rect, data);

            result.ContextMenuSetUp(cmd);
            ownerControl.canvas.Children.Add(result);
            figures.Add(result);

            return(result);
        }
        public void OnLostFocus(object sender, EventArgs e)
        {
            SimpleFigures obj = sender as SimpleFigures;

            if (obj != null)
            {
                obj.PropertyPanel.Hide();
                obj.DeselectControl();
            }
            StackControl = null;
        }
        public void OnLostFocus(object sender, EventArgs e)
        {
            Keyboard.ClearFocus();
            SimpleFigures obj = sender as SimpleFigures;

            if (obj != null)
            {
                obj.Focusable = false;
                obj.DeselectControl();
            }
            StackControl = null;
        }
        public static Control Render(Control ownerControl, Graphics g, Point p1, Point p2)
        {
            Control result = null;

            switch (xData.Type)
            {
            case ShapeType.LINE:
                result = new SimpleFigures(p1.X, p1.Y, p2.X, p2.Y,
                                           xData.LineColor, xData.LineWidth, ShapeType.LINE);
                ownerControl.Controls.Add(result);
                figures.Add(ownerControl.Controls.Count - 1, result);
                break;

            case ShapeType.ELLIPSE:
                result = new SimpleFigures(p1.X, p1.Y, p2.X, p2.Y,
                                           xData.LineColor, xData.LineWidth, ShapeType.ELLIPSE);
                ownerControl.Controls.Add(result);
                figures.Add(ownerControl.Controls.Count - 1, result);
                break;

            case ShapeType.RECTANGLE:
                result = new SimpleFigures(p1.X, p1.Y, p2.X, p2.Y,
                                           xData.LineColor, xData.LineWidth, ShapeType.RECTANGLE);
                ownerControl.Controls.Add(result);
                figures.Add(ownerControl.Controls.Count - 1, result);
                break;

            case ShapeType.CRECTANGLE:
                result = new SimpleFigures(p1.X, p1.Y, p2.X, p2.Y,
                                           xData.LineColor, xData.LineWidth, ShapeType.CRECTANGLE);
                ownerControl.Controls.Add(result);
                figures.Add(ownerControl.Controls.Count - 1, result);
                break;

            case ShapeType.MULTILINE:
                result = new SimpleFigures(0, 0, 0, 0, xData.LineColor, xData.LineWidth, ShapeType.MULTILINE, xData.Path.ToArray());
                ownerControl.Controls.Add(result);
                figures.Add(ownerControl.Controls.Count - 1, result);
                break;

            default:
                throw new InvalidEnumArgumentException();
            }

            return(result);
        }
Example #14
0
        protected List <Figure> GetListOfFigures(List <Control> controls)
        {
            List <Figure> figures = new List <Figure>();

            foreach (var item in controls)
            {
                using (SimpleFigures sf = (SimpleFigures)item)
                {
                    Figure f = new Figure();
                    f.Bounds    = item.Bounds;
                    f.PenWidth  = sf.data.LineWidth;
                    f.Color     = sf.data.LineColor.ToArgb();
                    f.Path      = sf.data.Path.ToArray();
                    f.ShapeType = sf.data.Type;
                    figures.Add(f);
                }
            }

            return(figures);
        }
Example #15
0
        public static void Draw(UIElement[] elems, XCommand cmd)
        {
            cmd.canvasVector = TabControlVector.tabCanvases[TabControlVector.nameLast];
            foreach (var item in elems)
            {
                cmd.canvasVector.canvas.Children.Add(item);
            }


            DrawingVector2DTool.figures = new List <UIElement>();
            for (int i = 0; i < cmd.canvasVector.canvas.Children.Count; ++i)
            {
                SimpleFigures fi = cmd.canvasVector.canvas.Children[i] as SimpleFigures;
                fi.GainFocus   += cmd.canvasVector.OnGainFocus;
                fi.LostFocus   += cmd.canvasVector.OnLostFocus;
                fi.FigurePaste += cmd.canvasVector.OnFigurePaste;

                DrawingVector2DTool.figures.Add(cmd.canvasVector.canvas.Children[i]);
            }
        }
Example #16
0
        protected List <Figure> GetListOfFigures(List <UIElement> controls)
        {
            List <Figure> figures = new List <Figure>();

            foreach (var item in controls)
            {
                SimpleFigures sf = (SimpleFigures)item;
                Figure        f  = new Figure();
                f.Bounds   = sf.Margin;
                f.PenWidth = sf.data.LineWidth;
                f.Color    = new byte[4] {
                    sf.data.LineColor.A, sf.data.LineColor.R, sf.data.LineColor.G, sf.data.LineColor.B
                };
                f.Path      = sf.data.Path.ToArray();
                f.ShapeType = sf.data.Type;
                figures.Add(f);
            }

            return(figures);
        }
        public void OnFigurePaste(object sender, EventArgs e)
        {
            Figure obj     = sender as Figure;
            XData  newData = new XData();

            newData.LineColor = Color.FromArgb(obj.Color[0], obj.Color[1], obj.Color[2], obj.Color[3]);
            newData.LineWidth = obj.PenWidth;
            newData.Type      = obj.ShapeType;
            newData.Path      = obj.Path.ToList();

            SimpleFigures ctrl = (SimpleFigures)DrawingVector2DTool.Render(this,
                                                                           obj.Bounds, newData, cmd);

            ctrl.GainFocus   += this.OnGainFocus;
            ctrl.LostFocus   += this.OnLostFocus;
            ctrl.FigurePaste += this.OnFigurePaste;

            ctrl.ContextMenu_Color.Click     += new RoutedEventHandler(cmd.aColor.Action);
            ctrl.ContextMenu_PenWidth.Click  += new RoutedEventHandler(cmd.aWidth.Action);
            ctrl.ContextMenu_ShapeType.Click += new RoutedEventHandler(cmd.aType.Action);
        }
        public void OnFigurePaste(object sender, EventArgs e)
        {
            Figure obj     = sender as Figure;
            XData  newData = new XData();

            newData.LineColor = Color.FromArgb(obj.Color);
            newData.LineWidth = obj.PenWidth;
            newData.Type      = obj.ShapeType;
            newData.Path      = obj.Path.ToList();

            SimpleFigures ctrl = (SimpleFigures)DrawingVector2DTool.Render(this,
                                                                           new Rectangle(new Point(obj.Bounds.X + 20, obj.Bounds.Y + 20), obj.Bounds.Size), newData, cmd);

            ctrl.GainFocus   += this.OnGainFocus;
            ctrl.LostFocus   += this.OnLostFocus;
            ctrl.FigurePaste += this.OnFigurePaste;
            this.Controls[Controls.Count - 1].BringToFront();

            ctrl.ContextMenu_Color.Click     += new EventHandler(cmd.aColor.Action);
            ctrl.ContextMenu_PenWidth.Click  += new EventHandler(cmd.aWidth.Action);
            ctrl.ContextMenu_ShapeType.Click += new EventHandler(cmd.aType.Action);
            ctrl.PropertyPanel = (this.Parent.Parent.Parent.Parent as MiniPaintV).propertyPanel;
        }