Ejemplo n.º 1
0
        public override Geometry GetGeometry()
        {
            GeometryGroup group = new GeometryGroup();

            for (int a = 0; a < Texts.Count; a++)
            {
                if (!string.IsNullOrEmpty(Texts[a]))
                {
                    FormattedText formattedText = NewFormattedText(Texts[a]);
                    double        locx          = 0;
                    double        locy          = 0;
                    Rect          bounds        = ShapeComponent.GetGeometry().GetRenderBounds(new Pen(), 0, ToleranceType.Absolute);
                    double        width         = bounds.Width;
                    double        height        = bounds.Height;
                    if (a % 2 == 0)
                    {
                        locx = (width / 2) - (formattedText.Width / 2);
                    }
                    if (a % 2 == 1)
                    {
                        locy = (height / 2) - (formattedText.Height / 2);
                    }
                    if (a % 4 == 2)
                    {
                        locy = width - formattedText.Height;
                    }
                    if (a % 4 == 1)
                    {
                        locx = height - formattedText.Width;
                    }
                    group.Children.Add(formattedText.BuildGeometry(new Point(locx, locy)));
                }
            }
            return(group);
        }
Ejemplo n.º 2
0
        public GeometryGroup GetGeometryGroup()
        {
            GeometryGroup group = new GeometryGroup();

            group.Children.Add(GetGeometry());
            group.Children.Add(ShapeComponent.GetGeometry());
            return(group);
        }
Ejemplo n.º 3
0
        private static void GetNewLocationAndSize(ShapeComponent shape, double offset_x, double offset_y, out double new_x, out double new_y, out double new_width, out double new_height)
        {
            new_x      = shape.Location.X;
            new_y      = shape.Location.Y;
            new_width  = shape.ActualWidth;
            new_height = shape.ActualHeight;

            // Update the rectangle.
            switch (shape.MousePosition)
            {
            case MousePositionType.Body:
                new_x += offset_x;
                new_y += offset_y;
                break;

            case MousePositionType.UL:
                new_x      += offset_x;
                new_y      += offset_y;
                new_width  -= offset_x;
                new_height -= offset_y;
                break;

            case MousePositionType.UR:
                new_y      += offset_y;
                new_width  += offset_x;
                new_height -= offset_y;
                break;

            case MousePositionType.DR:
                new_width  += offset_x;
                new_height += offset_y;
                break;

            case MousePositionType.DL:
                new_x      += offset_x;
                new_width  -= offset_x;
                new_height += offset_y;
                break;

            case MousePositionType.L:
                new_x     += offset_x;
                new_width -= offset_x;
                break;

            case MousePositionType.R:
                new_width += offset_x;
                break;

            case MousePositionType.B:
                new_height += offset_y;
                break;

            case MousePositionType.T:
                new_y      += offset_y;
                new_height -= offset_y;
                break;
            }
        }
Ejemplo n.º 4
0
 private void SetNewGeometry()
 {
     Geometry = new GeometryGroup();
     //List<ShapeComponent> Nongroupshapes = GetShapesOfGroup();
     foreach (ShapeComponent component in Shapes)
     {
         if (component is InternalShape shape)
         {
             Geometry.Children.Add(shape.GetGeometry(shape.Location.X - Location.X, shape.Location.Y - Location.Y, shape.Width, shape.Height));
         }
         else if (component is ShapeGroup group)
         {
             if (group.Location.X > Location.X)
             {
                 group.Location = new Point(Location.X + 0.0001, group.Location.Y);
             }
             if (group.Location.Y > Location.Y)
             {
                 group.Location = new Point(group.Location.X, Location.Y + 0.0001);
             }
             if (group.Location.X > Location.X || group.Location.Y > Location.Y)
             {
                 group.SetNewGeometry();
             }
             foreach (var item in group.Geometry.Children)
             {
                 Geometry.Children.Add(item);
             }
         }
         else if (component is TextDecorator decorator)
         {
             //if (decorator.Location.X > Location.X)
             //{
             //    decorator.Location = new Point((decorator.Location.X - (decorator.Location.X - Location.X)) + 2, decorator.Location.Y);
             //}
             //if (decorator.Location.Y > Location.Y)
             //{
             //    decorator.Location = new Point(decorator.Location.X, (decorator.Location.Y - (decorator.Location.Y - Location.Y)) + 2);
             //}
             //if (decorator.Location.X > Location.X || decorator.Location.Y > Location.Y)
             //{
             //    decorator.SetNewGeometry();
             //}
             //foreach (var item in decorator.GetGeometryGroup().Children)
             //{
             //    Geometry.Children.Add(item);
             //}
             ShapeComponent decoratedShape = decorator.ShapeComponent;
             Geometry.Children.Add(decoratedShape.GetGeometry(decoratedShape.Location.X - Location.X, decoratedShape.Location.Y - Location.Y, decoratedShape.Width, decoratedShape.Height));
             Geometry texts = decorator.GetGeometry();
             texts.Transform = new TranslateTransform(decoratedShape.Location.X - Location.X, decoratedShape.Location.Y - Location.Y);
             Geometry.Children.Add(texts);
         }
     }
 }
Ejemplo n.º 5
0
 public void Add(ShapeComponent component)
 {
     Shapes.Add(component);
     if (Location.X > component.Location.X)
     {
         Location = new Point(component.Location.X, Location.Y);
     }
     if (Location.Y > component.Location.Y)
     {
         Location = new Point(Location.X, component.Location.Y);
     }
     SetNewGeometry();
 }
Ejemplo n.º 6
0
 private double SetLeftOfShape(InternalCanvas canvas, ShapeComponent shape, double new_x)
 {
     if (new_x < 0)
     {
         return(0);
     }
     else if (new_x > (canvas.ActualWidth - shape.ActualWidth))
     {
         return(canvas.ActualWidth - shape.ActualWidth);
     }
     else
     {
         return(new_x);
     }
 }
Ejemplo n.º 7
0
 private double SetTopOfShape(InternalCanvas canvas, ShapeComponent shape, double new_y)
 {
     if (new_y < 0)
     {
         return(0);
     }
     else if (new_y > (canvas.ActualHeight - shape.ActualHeight))
     {
         return(canvas.ActualHeight - shape.ActualHeight);
     }
     else
     {
         return(new_y);
     }
 }
Ejemplo n.º 8
0
 private void ExecuteMouseDown(InternalCanvas canvas)
 {
     mousePosition = Mouse.GetPosition(canvas);
     foreach (ShapeComponent canvasshape in canvas.Shapes)
     {
         if (canvasshape.IsMouseOver)
         {
             canvasshape.MousePosition = canvasshape.GetMousePositionType(mousePosition);
             shape        = canvasshape;
             oldLocation  = canvas.GetPositionOfShapeInCanvas(shape);
             oldHeight    = shape.Height;
             oldWidth     = shape.Width;
             shape.Stroke = Brushes.DarkBlue;
             break;
         }
     }
 }
Ejemplo n.º 9
0
        private List <ShapeComponent> ReadedLinesToShapes(int spaces = 0)
        {
            List <string>         texts       = null;
            List <ShapeComponent> loadeshapes = new List <ShapeComponent>();

            while (ReadedLines.Count > 0 && CheckAmountOfSpaces(ReadedLines.First()) == spaces)
            {
                List <string> splittedLines = ReadedLines.First().Split(' ').ToList();
                List <string> items         = splittedLines.GetRange(spaces, splittedLines.Count() - spaces);
                ReadedLines.Remove(ReadedLines.First());
                ShapeComponent loadedshape = null;
                if (items.First() == "group")
                {
                    loadedshape = GetGroup(spaces + 3);
                }
                else if (items.First() == InternalEllipse.getInstance().GetName())
                {
                    loadedshape = InternalShape.Load(InternalEllipse.getInstance(), items);
                }
                else if (items.First() == InternalRectangle.getInstance().GetName())
                {
                    loadedshape = InternalShape.Load(InternalRectangle.getInstance(), items);
                }
                else if (items.First() == "ornament")
                {
                    if (texts == null)
                    {
                        texts = new List <string>()
                        {
                            "", "", "", ""
                        };
                    }
                    texts[TextDecorator.GetLocation((TextDecorator.TextLocations)Enum.Parse(typeof(TextDecorator.TextLocations), items[1]))] = items[2].Trim('"');
                }
                if (texts != null && loadedshape != null)
                {
                    loadeshapes.Add(new TextDecorator(loadedshape, texts));
                    texts = null;
                }
                else if (loadedshape != null)
                {
                    loadeshapes.Add(loadedshape);
                }
            }
            return(loadeshapes);
        }
Ejemplo n.º 10
0
 public override void Save(SaveVisitor visitor)
 {
     visitor.Visit(this);
     ShapeComponent.Save(visitor);
 }
Ejemplo n.º 11
0
 public TextDecorator(ShapeComponent shapeComponent, List <string> texts) : base(shapeComponent)
 {
     Fill  = Brushes.DarkRed;
     Texts = texts;
     SetNewGeometry();
 }
Ejemplo n.º 12
0
 public bool Contains(ShapeComponent component)
 {
     return(Shapes.Contains(component));
 }
Ejemplo n.º 13
0
 public void Remove(ShapeComponent component)
 {
     Shapes.Remove(component);
 }
Ejemplo n.º 14
0
 public override void Resize(ResizeVisitor visitor)
 {
     visitor.Visit(this);
     ShapeComponent.Resize(visitor);
     //SetNewGeometry();
 }