Exemplo n.º 1
0
        //Gets the most upperleft and bottomright coordinates of shapes in a group recursively
        public XYXY GetGroupXYHW()
        {
            XYXY xyhw = new XYXY();

            foreach (Composite c in groupitems)
            {
                if (c.type != "Group")
                {
                    if (xyhw.sx != 746746)
                    {
                        xyhw.sx = MainPage.ReturnSmallest(xyhw.sx, c.x);
                    }
                    else
                    {
                        xyhw.sx = c.x;
                    }
                    if (xyhw.sy != 746746)
                    {
                        xyhw.sy = MainPage.ReturnSmallest(xyhw.sy, c.y);
                    }
                    else
                    {
                        xyhw.sy = c.y;
                    }
                    if (xyhw.ex != 746746)
                    {
                        xyhw.ex = MainPage.ReturnLargest(xyhw.ex, c.x + c.width);
                    }
                    else
                    {
                        xyhw.ex = c.x + c.width;
                    }
                    if (xyhw.ey != 746746)
                    {
                        xyhw.ey = MainPage.ReturnLargest(xyhw.ey, c.y + c.height);
                    }
                    else
                    {
                        xyhw.ey = c.y + c.height;
                    }
                }
                else
                {
                    XYXY rxyhw = c.GetGroupXYHW();
                    if (xyhw.sx != 746746)
                    {
                        xyhw.sx = MainPage.ReturnSmallest(xyhw.sx, c.x);
                    }
                    else
                    {
                        xyhw.sx = c.x;
                    }
                    if (xyhw.sy != 746746)
                    {
                        xyhw.sy = MainPage.ReturnSmallest(xyhw.sy, c.y);
                    }
                    else
                    {
                        xyhw.sy = c.y;
                    }
                    if (xyhw.ex != 746746)
                    {
                        xyhw.ex = MainPage.ReturnLargest(xyhw.ex, c.x + c.width);
                    }
                    else
                    {
                        xyhw.ex = c.x + c.width;
                    }
                    if (xyhw.ey != 746746)
                    {
                        xyhw.ey = MainPage.ReturnLargest(xyhw.ey, c.y + c.height);
                    }
                    else
                    {
                        xyhw.ey = c.y + c.height;
                    }
                }
            }
            return(xyhw);
        }
Exemplo n.º 2
0
        //Update after undo/redo or changes made
        public void Update(bool change)
        {
            //true means that an actual change has been made and needs to be stored in the history
            if (change)
            {
                timeindex++;;
                if (history.timeline.Count >= timeindex)
                {
                    history.timeline.RemoveRange(timeindex, history.timeline.Count - timeindex);
                }
                history.timeline.Add(new Snapshot(group.Copy(), itemcount));
            }
            //false means that the history needs to be read and written to the paintsurface
            else
            {
                group     = history.timeline[timeindex].composite.Copy();
                itemcount = history.timeline[timeindex].itemcount;
                paintSurface.Children.Clear();
                List <Composite> tosurface = history.timeline[timeindex].composite.Concatenate();
                foreach (Composite c in tosurface)
                {
                    if (c.type != "Group")
                    {
                        Strategy strategy = DrawEllipse.getInstance();
                        if (c.type == "Rectangle")
                        {
                            strategy = DrawRectangle.getInstance();
                        }
                        foreach (Ornament o in c.ornaments)
                        {
                            switch (o.position)
                            {
                            case "top":
                                strategy = new UpperOrnamentDecorator(strategy, o.ornament);
                                break;

                            case "bottom":
                                strategy = new LowerOrnamentDecorator(strategy, o.ornament);
                                break;

                            case "left":
                                strategy = new LeftOrnamentDecorator(strategy, o.ornament);
                                break;

                            case "right":
                                strategy = new RightOrnamentDecorator(strategy, o.ornament);
                                break;
                            }
                        }
                        DrawPackage drawpackage = new DrawPackage();
                        drawpackage.x            = c.x;
                        drawpackage.y            = c.y;
                        drawpackage.height       = c.height;
                        drawpackage.width        = c.width;
                        drawpackage.id           = c.id;
                        drawpackage.paintSurface = paintSurface;
                        Context context = new Context(strategy);
                        context.drawpackage = drawpackage;
                        Shape           shape = context.Draw();
                        SolidColorBrush brush = new SolidColorBrush();
                        if (IsSelected(c))
                        {
                            brush.Color = Colors.DarkSlateGray;
                        }
                        else
                        {
                            brush.Color = Colors.SlateGray;
                        }
                        shape.Fill                 = brush;
                        shape.PointerPressed      += mouseDown;
                        shape.PointerMoved        += mouseMove;
                        shape.PointerReleased     += mouseUp;
                        shape.PointerWheelChanged += mouseScroll;
                        paintSurface.Children.Add(shape);
                    }
                    else
                    {
                        Strategy strategy = DrawEllipse.getInstance();
                        foreach (Ornament o in c.ornaments)
                        {
                            switch (o.position)
                            {
                            case "top":
                                strategy = new UpperOrnamentDecorator(strategy, o.ornament);
                                break;

                            case "bottom":
                                strategy = new LowerOrnamentDecorator(strategy, o.ornament);
                                break;

                            case "left":
                                strategy = new LeftOrnamentDecorator(strategy, o.ornament);
                                break;

                            case "right":
                                strategy = new RightOrnamentDecorator(strategy, o.ornament);
                                break;
                            }
                        }
                        DrawPackage drawpackage = new DrawPackage();
                        XYXY        xyxy        = c.GetGroupXYHW();
                        drawpackage.x            = xyxy.sx;
                        drawpackage.y            = xyxy.sy;
                        drawpackage.height       = xyxy.ey - xyxy.sy;
                        drawpackage.width        = xyxy.ex - xyxy.sx;
                        drawpackage.id           = c.id;
                        drawpackage.paintSurface = paintSurface;
                        Context context = new Context(strategy);
                        context.drawpackage = drawpackage;
                        Shape shape = context.Draw();
                    }
                }
            }
        }