public bool SelectShapes()
        {
            if (this.shapes.Count() == 0)
            {
                return(false);
            }

            Shape shape = this.shapes.Last();

            if (shape is Select)
            {
                Select select = (Select)shape;

                this.RemoveSelect();

                this.selectedShapes = select.FindContainedShapes(this.shapes.Where(x => !(x is Select)).ToList(), this.Width);

                if (this.selectedShapes.Shapes.Count > 0)
                {
                    this.selectedShapes.Select();
                }
            }

            this.Invalidate(); // Update the canvas

            return(this.selectedShapes.Shapes.Count > 1);
        }
Beispiel #2
0
        public bool Contains(Shape shape, int width)
        {
            if (shape is FreeLine)
            {
                return(Geometry.FreeLineIntersectsSelect((FreeLine)shape, this));
            }
            else if (shape is Line)
            {
                return(Geometry.LineIntersectsSelect((Line)shape, this));
            }
            else if (shape is Rectangle || shape is Square)
            {
                return(Geometry.RectangleIntersectsSelect((Rectangle)shape, this));
            }
            else if (shape is Circle || shape is Ellipse)
            {
                return(Geometry.EllipseIntersectsSelect((Ellipse)shape, this, (shape is Circle)));
            }
            else if (shape is Polygon)
            {
                bool    isSelected = false;
                Polygon selectedP  = (Polygon)shape;

                foreach (Line line in selectedP.lines)
                {
                    isSelected = Geometry.LineIntersectsSelect(line, this);

                    if (isSelected == true)
                    {
                        break;
                    }
                }

                return(isSelected);
            }
            else if (shape is GroupedShape)
            {
                GroupedShape groupedShape = (GroupedShape)shape;

                foreach (Shape subShape in groupedShape.Shapes)
                {
                    if (this.Contains(subShape, width))
                    {
                        return(true);
                    }
                }
            }

            return(false);
        }
Beispiel #3
0
        public GroupedShape FindContainedShapes(List <Shape> shapes, int width)
        {
            GroupedShape selectedShapes = new GroupedShape();

            foreach (Shape shape in shapes)
            {
                if (this.Contains(shape, width))
                {
                    shape.Select();
                    selectedShapes.Shapes.Add(shape);
                }
            }

            return(selectedShapes);
        }
        public void RemoveSelect()
        {
            this.shapes.RemoveAll(x => x is Select);

            foreach (Shape shape in this.shapes)
            {
                if (shape.IsSelected)
                {
                    shape.Deselect();
                }
            }

            this.selectedShapes = new GroupedShape();

            this.Invalidate();
        }
        public void Cut()
        {
            //this.RemoveSelect();
            this.clipBoard = selectedShapes;


            Console.WriteLine("clipboard " + this.clipBoard.Shapes.Count);
            Console.WriteLine("shapes " + this.shapes.Count);

            this.undoStack.Push(new List <Shape>(this.shapes));
            this.shapes.Remove(clipBoard);
            foreach (Shape s in clipBoard.Shapes)
            {
                this.shapes.Remove(s);
            }
            Console.WriteLine("shapes after " + this.shapes.Count);


            this.Invalidate();
        }
Beispiel #6
0
        private bool EnableUngroupButton(Shape shape)
        {
            if (this.canvas.Shapes.Count == 0)
            {
                return(false);
            }

            if (shape is GroupedShape)
            {
                GroupedShape selectedShapes = (GroupedShape)shape;

                if (selectedShapes.Shapes.Count == 1 && selectedShapes.Shapes.First() is GroupedShape)
                {
                    return(EnableUngroupButton(selectedShapes.Shapes.First()));
                }

                return(selectedShapes.Shapes.Count > 1);
            }

            return(false);
        }
        public void UngroupSelectedShapes(Shape shape)
        {
            if (shape is GroupedShape)
            {
                this.undoStack.Push(new List <Shape>(this.shapes));
                GroupedShape groupedShape = (GroupedShape)shape;

                this.shapes.Remove(groupedShape);

                foreach (Shape subShape in groupedShape.Shapes)
                {
                    this.shapes.Remove(subShape);
                    if (subShape is GroupedShape)
                    {
                        this.shapes.Remove(subShape);
                        this.UngroupSelectedShapes(subShape);
                    }
                    else
                    {
                        this.shapes.Add(subShape);
                    }
                }
            }
        }