示例#1
0
    /// <summary>Draws the graphics primitive using a given graphics render context.</summary>
    /// <param name="renderContext">The render context that should be used to draw the graphics primitive.</param>
    /// <param name="instanceCount">The number of instances that should be drawn.</param>
    /// <exception cref="ArgumentNullException"><paramref name="renderContext" /> is <c>null</c>.</exception>
    public void Draw(GraphicsRenderContext renderContext, uint instanceCount = 1)
    {
        ThrowIfNull(renderContext);

        renderContext.BindPipeline(Pipeline);

        if (PipelineDescriptorSet is GraphicsPipelineDescriptorSet pipelineDescriptorSet)
        {
            renderContext.BindPipelineDescriptorSet(pipelineDescriptorSet);
        }

        var vertexBufferView = VertexBufferView;

        renderContext.BindVertexBufferView(vertexBufferView);

        if (IndexBufferView is GraphicsBufferView indexBufferView)
        {
            renderContext.BindIndexBufferView(indexBufferView);
            renderContext.DrawIndexed(indicesPerInstance: (uint)(indexBufferView.ByteLength / indexBufferView.BytesPerElement), instanceCount);
        }
        else
        {
            renderContext.Draw(verticesPerInstance: (uint)(vertexBufferView.ByteLength / vertexBufferView.BytesPerElement), instanceCount);
        }
    }
示例#2
0
        void IGraphicsRenderer.Render(GraphicsRenderContext context, ILayoutArea area)
        {
            _layoutArea = area;
            const string ErrorMsg = "IGraphicsRenderer was configured improperly.";

            CalendarContentRange content = area.ContentRange as CalendarContentRange;

            if (content == null)
            {
                Trace.TraceError(ErrorMsg);
                return;
            }

            CalendarDataRegion calendar = content.Owner as CalendarDataRegion;

            if (calendar == null)
            {
                Trace.TraceError(ErrorMsg);
                return;
            }

            if (context.DoContent)
            {
                Render(content, context.Canvas, new RectangleF(area.Left, area.Top, area.Width, area.Height));
            }
        }
示例#3
0
        /// <summary>
        /// Exports the specified <see cref="PlotModel" /> to a <see cref="Bitmap" />.
        /// </summary>
        /// <param name="model">The model to export.</param>
        /// <returns>A bitmap.</returns>
        public Bitmap ExportToBitmap(IPlotModel model)
        {
            var bm = new Bitmap(this.Width, this.Height);

            using (var g = Graphics.FromImage(bm))
            {
                if (model.Background.IsVisible())
                {
                    using (var brush = model.Background.ToBrush())
                    {
                        g.FillRectangle(brush, 0, 0, this.Width, this.Height);
                    }
                }

                using (var rc = new GraphicsRenderContext(g)
                {
                    RendersToScreen = false
                })
                {
                    model.Update(true);
                    model.Render(rc, new OxyRect(0, 0, this.Width, this.Height));
                }

                bm.SetResolution((float)this.Resolution, (float)this.Resolution);
                return(bm);
            }
        }
示例#4
0
        static void CreateBitmap(int size, IconRenderer iconRenderer, string fileName, double cornerRadius = 0)
        {
            using (var bm = new Bitmap(size, size, PixelFormat.Format32bppArgb))
            {
                using (var g = Graphics.FromImage(bm))
                {
                    g.TextRenderingHint  = TextRenderingHint.AntiAliasGridFit;
                    g.SmoothingMode      = SmoothingMode.AntiAlias;
                    g.InterpolationMode  = InterpolationMode.HighQualityBicubic;
                    g.PixelOffsetMode    = PixelOffsetMode.HighQuality;
                    g.CompositingQuality = CompositingQuality.HighQuality;
                    g.CompositingMode    = CompositingMode.SourceOver;
                    using (var rc = new GraphicsRenderContext(g)
                    {
                        RendersToScreen = false
                    })
                    {
                        g.Clear(Color.Transparent);

                        if (cornerRadius > 0)
                        {
                            // TODO: no antialiasing on the clipping path?
                            var path = GetRoundedRect(new RectangleF(0, 0, size, size), (float)cornerRadius);
                            g.SetClip(path, CombineMode.Replace);
                        }

                        iconRenderer.Render(rc, size);
                    }

                    bm.Save(fileName, System.Drawing.Imaging.ImageFormat.Png);
                }
            }
        }
示例#5
0
 /// <summary>
 /// Initializes a new instance of the <see cref="ISvgRenderer"/> class.
 /// </summary>
 public SvgRenderer(GraphicsRenderContext context, RectangleF bounds)
 {
     _innerGraphics = context.Canvas;
     _bounds        = bounds;
     _innerGraphics.PushState();
     _innerGraphics.IntersectClip(bounds);
 }
示例#6
0
        /// <summary>
        /// Creates an SVG string.
        /// </summary>
        /// <param name="model">The model.</param>
        /// <param name="width">The width (points).</param>
        /// <param name="height">The height (points).</param>
        /// <param name="isDocument">if set to <c>true</c>, the xml headers will be included (?xml and !DOCTYPE).</param>
        /// <returns>A <see cref="string" />.</returns>
        public static string ToSvg(this PlotModel model, double width, double height, bool isDocument)
        {
            var rc = new GraphicsRenderContext {
                RendersToScreen = false
            };

            return(SvgExporter.ExportToString(model, width, height, isDocument, rc));
        }
示例#7
0
 static void CreateSvg(int size, IconRenderer iconRenderer, string fileName)
 {
     using (var bm = new Bitmap(size, size))
     {
         using (var grx = new GraphicsRenderContext(Graphics.FromImage(bm)))
         {
             using (var s = File.Create(fileName))
             {
                 using (var rc = new SvgRenderContext(s, size, size, true, grx, OxyColors.Transparent))
                 {
                     iconRenderer.Render(rc, size);
                 }
             }
         }
     }
 }
示例#8
0
        /// <summary>
        /// Initializes a new instance of the <see cref="Plot"/> class.
        /// </summary>
        public Plot(Base parent)
            : base(parent)
        {
            KeyboardInputEnabled = true;

            this.renderContext = new GraphicsRenderContext();

            // ReSharper disable DoNotCallOverridableMethodsInConstructor
            this.DoubleBuffered = true;
            // ReSharper restore DoNotCallOverridableMethodsInConstructor
            this.KeyboardPanHorizontalStep = 0.1;
            this.KeyboardPanVerticalStep   = 0.1;
            this.PanCursor            = Cursors.Hand;
            this.ZoomRectangleCursor  = Cursors.SizeNWSE;
            this.ZoomHorizontalCursor = Cursors.SizeWE;
            this.ZoomVerticalCursor   = Cursors.SizeNS;
        }
示例#9
0
        public static void Export(PlotModel model, string fileName, int width, int height, Brush background = null)
        {
            using (var bm = new Bitmap(width, height))
            {
                using (Graphics g = Graphics.FromImage(bm))
                {
                    if (background != null)
                    {
                        g.FillRectangle(background, 0, 0, width, height);
                    }

                    var rc = new GraphicsRenderContext {
                        RendersToScreen = false
                    };
                    rc.SetGraphicsTarget(g);
                    model.Update();
                    model.Render(rc, width, height);
                    bm.Save(fileName, ImageFormat.Png);
                }
            }
        }
        protected override void OnPaint(PaintEventArgs e)
        {
            base.OnPaint(e);

            var rc = new GraphicsRenderContext(this, e.Graphics, e.ClipRectangle);

            if (model != null)
            {
                model.Render(rc);
            }
            if (zoomRectangle != Rectangle.Empty)
            {
                using (var zoomBrush = new SolidBrush(Color.FromArgb(0x40, 0xFF, 0xFF, 0x00)))
                    using (var zoomPen = new Pen(Color.Black))
                    {
                        zoomPen.DashPattern = new float[] { 3, 1 };
                        e.Graphics.FillRectangle(zoomBrush, zoomRectangle);
                        e.Graphics.DrawRectangle(zoomPen, zoomRectangle);
                    }
            }
        }
示例#11
0
            void IGraphicsRenderer.Render(GraphicsRenderContext context, ILayoutArea area)
            {
                var    reportItem = (SvgImage)area.ReportItem;
                string svg        = Convert.ToString(reportItem._properties.GetValue("Svg")).Trim();

                var doc = new XmlDocument();

                try
                {
                    doc.LoadXml(svg);
                }
                catch (XmlException)
                {
                    throw new Exception(Properties.Resources.ExceptionMessage);
                }

                var svgDocument = SvgDocument.Open(doc);

                using (var renderer = new SvgRenderer(context, new RectangleF(area.Left, area.Top, area.Width, area.Height)))
                    svgDocument.Draw(renderer);
            }
示例#12
0
        public static void Render(IReport report, TextWriter writer, TxtSettings settings)
        {
            if (report == null)
            {
                throw new ArgumentNullException(nameof(report));
            }

            var settingsFontSizeTwips = new Size(settings.FontSizePt.Width * 20, settings.FontSizePt.Height * 20);

            var metricsProvider = new TxtMetricsProvider(settingsFontSizeTwips);
            var targetDevice    = (ITargetDevice) new TargetDevice(TargetDeviceKind.Export, InteractivityType.None, null, false, true);
            var layoutTree      = GenerateLayoutTree(report, targetDevice, metricsProvider);

            var page = layoutTree.Pages.First();

            var canvas = new TxtDrawingCanvas(settingsFontSizeTwips, settings.LineEnding);

            var context = new GraphicsRenderContext(targetDevice, canvas, metricsProvider, RenderersFactory.Instance, null);

            Renderer.RenderPage(context, page);

            canvas.Write(writer);
        }
示例#13
0
 protected override void Draw(GraphicsRenderContext renderContext)
 {
     _quadPrimitive.Draw(renderContext);
     base.Draw(renderContext);
 }
示例#14
0
 /// <summary>
 /// Creates an SVG string.
 /// </summary>
 /// <param name="model">The model.</param>
 /// <param name="width">The width (points).</param>
 /// <param name="height">The height (points).</param>
 /// <param name="isDocument">if set to <c>true</c>, the xml headers will be included (?xml and !DOCTYPE).</param>
 /// <returns>A <see cref="string" />.</returns>
 public static string ToSvg(this PlotModel model, double width, double height, bool isDocument)
 {
     var rc = new GraphicsRenderContext { RendersToScreen = false };
     return SvgExporter.ExportToString(model, width, height, isDocument, rc);
 }
示例#15
0
 protected virtual void Draw(GraphicsRenderContext renderContext)
 {
 }
示例#16
0
 protected override void Draw(GraphicsRenderContext graphicsRenderContext)
 {
     _sierpinskiPrimitive.Draw(graphicsRenderContext);
     base.Draw(graphicsRenderContext);
 }
示例#17
0
 protected override void Draw(GraphicsRenderContext graphicsRenderContext)
 {
     _trianglePrimitive.Draw(graphicsRenderContext);
     base.Draw(graphicsRenderContext);
 }
示例#18
0
 /// <summary>
 /// Initializes a new instance of the <see cref = "Plot" /> class.
 /// </summary>
 public Plot()
 {
     this.DoubleBuffered = true;
     this.Model          = new PlotModel();
     this.rc             = new GraphicsRenderContext(); // e.ClipRectangle
 }
示例#19
0
        protected override void OnPaint(PaintEventArgs e)
        {
            base.OnPaint(e);

            var rc = new GraphicsRenderContext(this, e.Graphics, e.ClipRectangle);
            if (model != null)
                model.Render(rc);
            if (zoomRectangle != Rectangle.Empty)
            {
                using (var zoomBrush = new SolidBrush(Color.FromArgb(0x40, 0xFF, 0xFF, 0x00)))
                using (var zoomPen = new Pen(Color.Black))
                {
                    zoomPen.DashPattern = new float[] { 3, 1 };
                    e.Graphics.FillRectangle(zoomBrush, zoomRectangle);
                    e.Graphics.DrawRectangle(zoomPen, zoomRectangle);
                }
            }
        }
示例#20
0
 /// <summary>
 /// Initializes a new instance of the <see cref = "Plot" /> class.
 /// </summary>
 public Plot()
 {
     this.DoubleBuffered = true;
     this.Model = new PlotModel();
     this.rc = new GraphicsRenderContext(); // e.ClipRectangle
 }