Ejemplo n.º 1
0
        /// <summary>
        /// 
        /// </summary>
        /// <param name="container"></param>
        /// <param name="renderer"></param>
        /// <returns></returns>
        private static Viewbox ToViewbox(Container container, IRenderer renderer)
        {
            var visual = new DrawingVisual();

            using (var dc = visual.RenderOpen())
            {
                renderer.Draw(dc, container, container.Properties, null);
            }

            visual.Drawing.Freeze();

            var host = new VisualHost()
            {
                Width = container.Width,
                Height = container.Height
            };

            host.Visuals.Add(visual);

            var vb = new Viewbox()
            {
                Stretch = Stretch.Uniform
            };

            vb.Child = host;

            return vb;
        }
Ejemplo n.º 2
0
 /// <summary>
 /// 
 /// </summary>
 /// <param name="gfx"></param>
 /// <param name="container"></param>
 private void DrawBackgroundInternal(Graphics gfx, Container container)
 {
     Brush brush = ToSolidBrush(container.Background);
     var rect = Rect2.Create(0, 0, container.Width, container.Height);
     gfx.FillRectangle(
         brush,
         _scaleToPage(rect.X),
         _scaleToPage(rect.Y),
         _scaleToPage(rect.Width),
         _scaleToPage(rect.Height));
     brush.Dispose();
 }
Ejemplo n.º 3
0
 /// <summary>
 /// 
 /// </summary>
 /// <param name="gfx"></param>
 /// <param name="container"></param>
 /// <param name="db"></param>
 /// <param name="r"></param>
 public void Draw(object gfx, Container container, ImmutableArray<ShapeProperty> db, Record r)
 {
     foreach (var layer in container.Layers)
     {
         if (layer.IsVisible)
         {
             Draw(gfx, layer, db, r);
         }
     }
 }
Ejemplo n.º 4
0
 /// <summary>
 /// 
 /// </summary>
 /// <param name="container"></param>
 /// <param name="ic"></param>
 public void SetClipboard(Container container, IImageCache ic)
 {
     try
     {
         using (var bitmap = new Bitmap((int)container.Width, (int)container.Height))
         {
             using (var ms = MakeMetafileStream(bitmap, container, ic))
             {
                 var data = new WPF.DataObject();
                 data.SetData(WPF.DataFormats.EnhancedMetafile, ms);
                 WPF.Clipboard.SetDataObject(data, true);
             }
         }
     }
     catch (Exception ex)
     {
         Debug.Print(ex.Message);
         Debug.Print(ex.StackTrace);
     }
 }
Ejemplo n.º 5
0
 /// <summary>
 /// 
 /// </summary>
 /// <param name="path"></param>
 /// <param name="container"></param>
 /// <param name="ic"></param>
 public void Save(string path, Container container, IImageCache ic)
 {
     using (var bitmap = new Bitmap((int)container.Width, (int)container.Height))
     {
         using (var ms = MakeMetafileStream(bitmap, container, ic))
         {
             using (var fs = File.Create(path))
             {
                 ms.WriteTo(fs);
             }
         }
     }
 }
Ejemplo n.º 6
0
        /// <summary>
        /// 
        /// </summary>
        /// <param name="bitmap"></param>
        /// <param name="container"></param>
        /// <param name="ic"></param>
        /// <returns></returns>
        public MemoryStream MakeMetafileStream(
            Bitmap bitmap,
            Container container,
            IImageCache ic)
        {
            var g = default(Graphics);
            var mf = default(Metafile);
            var ms = new MemoryStream();

            try
            {
                using (g = Graphics.FromImage(bitmap))
                {
                    var hdc = g.GetHdc();
                    mf = new Metafile(ms, hdc);
                    g.ReleaseHdc(hdc);
                }

                using (g = Graphics.FromImage(mf))
                {
                    var r = new EmfRenderer(72.0 / 96.0);
                    r.State.ImageCache = ic;

                    g.SmoothingMode = SmoothingMode.HighQuality;
                    g.PixelOffsetMode = PixelOffsetMode.HighQuality;
                    g.TextRenderingHint = TextRenderingHint.ClearTypeGridFit;
                    g.CompositingQuality = CompositingQuality.HighQuality;
                    g.InterpolationMode = InterpolationMode.HighQualityBicubic;

                    g.PageUnit = GraphicsUnit.Display;

                    if (container.Template != null)
                    {
                        r.Draw(g, container.Template, container.Properties, null);
                    }

                    r.Draw(g, container, container.Properties, null);
                    r.ClearCache(isZooming: false);
                }
            }
            finally
            {
                if (g != null)
                {
                    g.Dispose();
                }

                if (mf != null)
                {
                    mf.Dispose();
                }
            }
            return ms;
        }
Ejemplo n.º 7
0
 /// <summary>
 /// 
 /// </summary>
 /// <param name="item"></param>
 public void OnCopy(object item)
 {
     if (item is Container)
     {
         var container = item as Container;
         _containerToCopy = container;
         _documentToCopy = default(Document);
     }
     else if (item is Document)
     {
         var document = item as Document;
         _containerToCopy = default(Container);
         _documentToCopy = document;
     }
     else if (item is EditorContext || item == null)
     {
         OnCopy();
     }
 }
Ejemplo n.º 8
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="container"></param>
        /// <returns></returns>
        public Container Clone(Container container)
        {
            try
            {
                var template = container.Template;
                var json = _serializer.Serialize(container);
                if (!string.IsNullOrEmpty(json))
                {
                    var clone = _serializer.Deserialize<Container>(json);
                    if (clone != null)
                    {
                        var shapes = clone.Layers.SelectMany(l => l.Shapes);
                        TryToRestoreStyles(shapes);
                        TryToRestoreRecords(shapes);
                        clone.Template = template;
                        return clone;
                    }
                }
            }
            catch (Exception ex)
            {
                if (_editor.Log != null)
                {
                    _editor.Log.LogError("{0}{1}{2}",
                        ex.Message,
                        Environment.NewLine,
                        ex.StackTrace);
                }
            }

            return null;
        }
Ejemplo n.º 9
0
 /// <summary>
 /// 
 /// </summary>
 /// <param name="name"></param>
 /// <param name="owner"></param>
 /// <param name="isVisible"></param>
 /// <returns></returns>
 public static Layer Create(string name, Container owner, bool isVisible = true)
 {
     return new Layer()
     {
         Name = name,
         Owner = owner,
         IsVisible = isVisible,
         Shapes = ImmutableArray.Create<BaseShape>()
     };
 }
Ejemplo n.º 10
0
 /// <summary>
 /// 
 /// </summary>
 /// <param name="project"></param>
 /// <param name="container"></param>
 private void CreateGrid(Project project, Container container)
 {
     var style = project
         .StyleLibraries.FirstOrDefault(g => g.Name == "Template")
         .Styles.FirstOrDefault(s => s.Name == "Grid");
     var layer = container.Layers.FirstOrDefault();
     var builder = layer.Shapes.ToBuilder();
     var grid = XRectangle.Create(
         0, 0,
         container.Width, container.Height,
         style,
         project.Options.PointShape);
     grid.IsStroked = false;
     grid.IsFilled = false;
     grid.IsGrid = true;
     grid.OffsetX = 30.0;
     grid.OffsetY = 30.0;
     grid.CellWidth = 30.0;
     grid.CellHeight = 30.0;
     grid.State &= ~ShapeState.Printable;
     builder.Add(grid);
     layer.Shapes = builder.ToImmutable();
 }
Ejemplo n.º 11
0
        /// <summary>
        /// 
        /// </summary>
        /// <param name="container"></param>
        public void Add(Container container)
        {
            if (container == null)
                return;

            container.PropertyChanged += ContainerObserver;

            if (container.Background != null)
            {
                container.Background.PropertyChanged += ContainerBackgroudObserver;
            }

            Verbose("Add Container: " + container.Name);

            if (container.Layers != null)
            {
                Add(container.Layers);
            }

            if (container.Properties != null)
            {
                Add(container.Properties);
            }

            //Add(container.WorkingLayer);
        }
Ejemplo n.º 12
0
 /// <summary>
 /// 
 /// </summary>
 /// <param name="dc"></param>
 /// <param name="container"></param>
 private void DrawBackgroundInternal(IDrawingContext dc, Container container)
 {
     Brush brush = ToSolidBrush(container.Background);
     var rect = new Rect(0, 0, container.Width, container.Height);
     dc.FillRectangle(brush, rect);
     // TODO: brush.Dispose();
 }
Ejemplo n.º 13
0
        /// <summary>
        /// 
        /// </summary>
        /// <param name="name"></param>
        /// <param name="width"></param>
        /// <param name="height"></param>
        /// <returns></returns>
        public static Container Create(string name = "Container", double width = 840, double height = 600)
        {
            var c = new Container()
            {
                Name = name,
                Width = width,
                Height = height,
                Background = ArgbColor.Create(0x00, 0xFF, 0xFF, 0xFF),
                Properties = ImmutableArray.Create<ShapeProperty>(),
                Layers = ImmutableArray.Create<Layer>()
            };

            var builder = c.Layers.ToBuilder();
            builder.Add(Layer.Create("Layer1", c));
            builder.Add(Layer.Create("Layer2", c));
            builder.Add(Layer.Create("Layer3", c));
            builder.Add(Layer.Create("Layer4", c));
            c.Layers = builder.ToImmutable();

            c.CurrentLayer = c.Layers.FirstOrDefault();
            c.WorkingLayer = Layer.Create("Working", c);
            c.HelperLayer = Layer.Create("Helper", c);

            return c;
        }
Ejemplo n.º 14
0
        /// <summary>
        /// 
        /// </summary>
        /// <param name="container"></param>
        /// <param name="rect"></param>
        /// <param name="treshold"></param>
        /// <returns></returns>
        public static ImmutableHashSet<BaseShape> HitTest(Container container, Rect2 rect, double treshold)
        {
            var builder = ImmutableHashSet.CreateBuilder<BaseShape>();

            var selection = new Vector2[]
            {
                new Vector2(rect.X, rect.Y),
                new Vector2(rect.X + rect.Width, rect.Y),
                new Vector2(rect.X + rect.Width, rect.Y + rect.Height),
                new Vector2(rect.X, rect.Y + rect.Height)
            };

            HitTest(container.CurrentLayer.Shapes.Reverse(), rect, selection, builder, treshold, 0, 0);

            return builder.ToImmutableHashSet();
        }
Ejemplo n.º 15
0
        /// <summary>
        /// 
        /// </summary>
        /// <param name="container"></param>
        /// <param name="p"></param>
        /// <param name="treshold"></param>
        /// <returns></returns>
        public static BaseShape HitTest(Container container, Vector2 p, double treshold)
        {
            var result = HitTest(container.CurrentLayer.Shapes.Reverse(), p, treshold, 0, 0);
            if (result != null)
            {
                return result;
            }

            return null;
        }