Exemple #1
0
 /// <summary>
 /// Resizes the GeometrySurface with the given size and redraws the GeometrySurface
 /// with the new geometry, outlines it with the given ICanvasStroke and fills it with
 /// the fill color and the background with the background brush.
 /// </summary>
 /// <param name="size">New size of the GeometrySurface</param>
 /// <param name="geometry">New CanvasGeometry to be applied to the GeometrySurface</param>
 /// <param name="stroke">ICanvasStroke defining the outline for the geometry</param>
 /// <param name="fillColor">Fill color for the geometry</param>
 /// <param name="backgroundBrush">Brush to fill the GeometrySurface background</param>
 public void Redraw(Size size, CanvasGeometry geometry, ICanvasStroke stroke, Color fillColor,
                    ICanvasBrush backgroundBrush)
 {
     // Resize the GeometrySurface
     _generator.ResizeDrawingSurface(_surfaceLock, _surface, size);
     // Set the size
     Size = _surface?.Size ?? new Size(0, 0);
     // Set the new geometry
     _geometry = geometry;
     // Set the new stroke
     _stroke = stroke;
     // Set the fill
     if (_fill is CanvasSolidColorBrush fillBrush)
     {
         fillBrush.Color = fillColor;
     }
     else
     {
         _fill = new CanvasSolidColorBrush(_generator.Device, fillColor);
     }
     // Set the backgroundBrush
     _backgroundBrush = backgroundBrush ?? new CanvasSolidColorBrush(_generator.Device, Colors.Transparent);
     // Redraw the GeometrySurface
     RedrawSurfaceInternal();
 }
Exemple #2
0
 /// <summary>
 /// Creates a CanvasRenderLayer with the specified geometry string, fill brush, outline brush,
 /// strokeWidth and stroke style.
 /// </summary>
 /// <param name="creator">ICanvasResourceCreator</param>
 /// <param name="geometryData">CanvasGeometry string definition.</param>
 /// <param name="brush">ICanvasBrush used to fill the rendered geometry.</param>
 /// <param name="strokeBrush">ICanvasBrush for the rendered geometry outline.</param>
 /// <param name="strokeWidth">Width of the rendered geometry outline.</param>
 /// <param name="strokeStyle">CanvasStrokeStyle</param>
 public CanvasRenderLayer(ICanvasResourceCreator creator, string geometryData, ICanvasBrush brush, ICanvasBrush strokeBrush,
                          float strokeWidth, CanvasStrokeStyle strokeStyle)
 {
     Geometry = String.IsNullOrWhiteSpace(geometryData) ? null : CanvasObject.CreateGeometry(creator, geometryData);
     Brush    = brush;
     Stroke   = new CanvasStroke(strokeBrush, strokeWidth, strokeStyle);
 }
Exemple #3
0
 /// <summary>
 /// Redraws the GeometrySurface by outlining the existing geometry with the
 /// given ICanvasStroke, filling it with the fill color and the background with the background color.
 /// </summary>
 /// <param name="stroke">ICanvasStroke defining the outline for the geometry</param>
 /// <param name="fillColor">Color with which the geometry is to be filled</param>
 /// <param name="backgroundColor">Color with which the GeometrySurface background is to be filled</param>
 public void Redraw(ICanvasStroke stroke, Color fillColor, Color backgroundColor)
 {
     // Set the new stroke
     _stroke = stroke;
     // Set the fill
     if (_fill is CanvasSolidColorBrush fillBrush)
     {
         fillBrush.Color = fillColor;
     }
     else
     {
         _fill = new CanvasSolidColorBrush(_generator.Device, fillColor);
     }
     // Set the backgroundBrush
     if (_backgroundBrush is CanvasSolidColorBrush backBrush)
     {
         backBrush.Color = backgroundColor;
     }
     else
     {
         _backgroundBrush = new CanvasSolidColorBrush(_generator.Device, backgroundColor);
     }
     // Redraw the GeometrySurface
     RedrawSurfaceInternal();
 }
 /// <summary>
 /// Redraws the GeometrySurface by outlining the existing geometry with
 /// the given ICanvasStroke
 /// </summary>
 /// <param name="stroke">ICanvasStroke defining the outline for the geometry</param>
 public void Redraw(ICanvasStroke stroke)
 {
     // Set the new stroke
     _stroke = stroke;
     // Redraw the GeometrySurface
     RedrawSurfaceInternal();
 }
 /// <summary>
 /// Draws a Squircle of the specified dimensions, using a CanvasStroke to define the stroke
 /// width, the stroke color and stroke style.
 /// </summary>
 /// <param name="session">CanvasDrawingSession</param>
 /// <param name="x">Offset of the top left corner of the  Squircle on the x-axis</param>
 /// <param name="y">Offset of the top left corner of the  Squircle on the y-axis</param>
 /// <param name="w">Width of the  Squircle</param>
 /// <param name="h">Height of the  Squircle</param>
 /// <param name="radiusX">Corner Radius on the x axis</param>
 /// <param name="radiusY">Corner Radius on the y axis</param>
 /// <param name="stroke">CanvasStroke defining the stroke width, the stroke
 /// color and stroke style.</param>
 public static void DrawSquircle(this CanvasDrawingSession session, float x, float y, float w, float h,
                                 float radiusX, float radiusY, ICanvasStroke stroke)
 {
     using (var geometry = CanvasObject.CreateSquircle(session.Device, x, y, w, h, radiusX, radiusY))
     {
         session.DrawGeometry(geometry, stroke);
     }
 }
 /// <summary>
 /// Redraws the GeometrySurface by filling the existing geometry with
 /// the given fill color and outlining it with the given ICanvasStroke.
 /// </summary>
 /// <param name="stroke">ICanvasStroke defining the outline for the geometry</param>
 /// <param name="fillColor">Color with which the geometry is to be filled</param>
 public void Redraw(ICanvasStroke stroke, Color fillColor)
 {
     // Set the new stroke
     _stroke = stroke;
     // Set the fill
     _fill = new CanvasSolidColorBrush(_generator.Device, fillColor);
     // Redraw the GeometrySurface
     RedrawSurfaceInternal();
 }
 /// <summary>
 /// Redraws the GeometrySurface by outlining the existing geometry with the
 /// given ICanvasStroke, filling it with the fill brush.
 /// </summary>
 /// <param name="stroke">ICanvasStroke defining the outline for the geometry</param>
 /// <param name="fillBrush">Brush with which the geometry is to be filled</param>
 public void Redraw(ICanvasStroke stroke, ICanvasBrush fillBrush)
 {
     // Set the new stroke
     _stroke = stroke;
     // Set the fill
     _fill = fillBrush ?? new CanvasSolidColorBrush(_generator.Device, Colors.Transparent);
     // Redraw the GeometrySurface
     RedrawSurfaceInternal();
 }
 /// <summary>
 /// Resizes the GeometrySurface with the given size and redraws the GeometrySurface
 /// with the new geometry and outlines it with the given ICanvasStroke.
 /// </summary>
 /// <param name="size">New size of the GeometrySurface</param>
 /// <param name="geometry">New CanvasGeometry to be applied to the GeometrySurface</param>
 /// <param name="stroke">ICanvasStroke defining the outline for the geometry</param>
 public void Redraw(Size size, CanvasGeometry geometry, ICanvasStroke stroke)
 {
     // Resize the GeometrySurface
     _generator.ResizeDrawingSurface(_surfaceLock, _surface, size);
     // Set the size
     Size = _surface?.Size ?? new Size(0, 0);
     // Set the new geometry
     _geometry = geometry;
     // Set the new stroke
     _stroke = stroke;
     // Redraw the GeometrySurface
     RedrawSurfaceInternal();
 }
 /// <summary>
 /// Resizes the GeometrySurface with the given size and redraws the GeometrySurface
 /// with the new geometry, outlines it with the given ICanvasStroke and fills
 /// it with the fill color.
 /// </summary>
 /// <param name="size">New size of the GeometrySurface</param>
 /// <param name="geometry">New CanvasGeometry to be applied to the GeometrySurface</param>
 /// <param name="stroke">ICanvasStroke defining the outline for the geometry</param>
 /// <param name="fillColor">Fill color for the geometry</param>
 public void Redraw(Size size, CanvasGeometry geometry, ICanvasStroke stroke, Color fillColor)
 {
     // Resize the GeometrySurface
     _generator.ResizeDrawingSurface(_surfaceLock, _surface, size);
     // Set the size
     Size = _surface?.Size ?? new Size(0, 0);
     // Set the new geometry
     _geometry = geometry;
     // Set the new stroke
     _stroke = stroke;
     // Set the fill
     _fill = new CanvasSolidColorBrush(_generator.Device, fillColor);
     // Redraw the GeometrySurface
     RedrawSurfaceInternal();
 }
 /// <summary>
 /// Constructor
 /// </summary>
 /// <param name="generator">ICompositionMaskGeneratorInternal object</param>
 /// <param name="size">Size of the GeometrySurface</param>
 /// <param name="geometry">Geometry of the GeometrySurface</param>
 /// <param name="stroke">Stroke for the geometry</param>
 /// <param name="fill">Brush to fill the geometry</param>
 /// <param name="backgroundBrush">Brush to fill the GeometrySurface background surface which is
 /// not covered by the geometry</param>
 public GeometrySurface(ICompositionGeneratorInternal generator, Size size, CanvasGeometry geometry,
                        ICanvasStroke stroke, ICanvasBrush fill, ICanvasBrush backgroundBrush)
 {
     _generator       = generator ?? throw new ArgumentNullException(nameof(generator), "CompositionGenerator cannot be null!");
     _surfaceLock     = new object();
     _geometry        = geometry;
     _stroke          = stroke;
     _fill            = fill;
     _backgroundBrush = backgroundBrush;
     // Create GeometrySurface
     _surface = _generator.CreateDrawingSurface(_surfaceLock, size);
     // Set the size
     Size = _surface?.Size ?? new Size(0, 0);
     // Subscribe to DeviceReplaced event
     _generator.DeviceReplaced += OnDeviceReplaced;
 }
 /// <summary>
 /// Redraws the GeometrySurface by filling the existing geometry with
 /// the given fill color and outlining it with the given ICanvasStroke.
 /// </summary>
 /// <param name="stroke">ICanvasStroke defining the outline for the geometry</param>
 /// <param name="fillColor">Color with which the geometry is to be filled</param>
 public void Redraw(ICanvasStroke stroke, Color fillColor)
 {
     // Set the new stroke
     _stroke = stroke;
     // Set the fill
     if (_fill is CanvasSolidColorBrush fillBrush)
     {
         fillBrush.Color = fillColor;
     }
     else
     {
         _fill = new CanvasSolidColorBrush(_generator.Device, fillColor);
     }
     // Redraw the GeometrySurface
     RedrawSurface();
 }
 /// <summary>
 /// Redraws the GeometrySurface by outlining the existing geometry with the
 /// given ICanvasStroke, filling it with the fill brush and the background with the background color.
 /// </summary>
 /// <param name="stroke">ICanvasStroke defining the outline for the geometry</param>
 /// <param name="fillBrush">Brush with which the geometry is to be filled</param>
 /// <param name="backgroundColor">Color with which the GeometrySurface background is to be filled</param>
 public void Redraw(ICanvasStroke stroke, ICanvasBrush fillBrush, Color backgroundColor)
 {
     // Set the new stroke
     _stroke = stroke;
     // Set the fill
     _fill = fillBrush ?? new CanvasSolidColorBrush(_generator.Device, Colors.Transparent);
     // Set the backgroundBrush
     if (_backgroundBrush is CanvasSolidColorBrush backBrush)
     {
         backBrush.Color = backgroundColor;
     }
     else
     {
         _backgroundBrush = new CanvasSolidColorBrush(_generator.Device, backgroundColor);
     }
     // Redraw the GeometrySurface
     RedrawSurface();
 }
        /// <summary>
        /// Disposes the resources used by the GeometrySurface
        /// </summary>
        public void Dispose()
        {
            _surface?.Dispose();
            _geometry?.Dispose();
            if (_generator != null)
            {
                _generator.DeviceReplaced -= OnDeviceReplaced;
            }
            _stroke.Brush.Dispose();
            _fill.Dispose();
            _backgroundBrush.Dispose();

            _stroke          = null;
            _fill            = null;
            _backgroundBrush = null;
            _surface         = null;
            _generator       = null;
            _geometry        = null;
        }
        /// <summary>
        /// Renders the layers of the CanvasElement, based on the specified dimensions,
        /// offset, padding and rotation, on a Canvas.
        /// </summary>
        /// <param name="session">CanvasDrawingSession</param>
        /// <param name="width">Target width of the rendered geometry</param>
        /// <param name="height">Target height of the rendered geometry</param>
        /// <param name="offset">Offset of the rendered geometry</param>
        /// <param name="padding">Padding of the surface on which the geometry
        /// is rendered.</param>
        /// <param name="rotation">Rotation angle (in radians) about the center of the
        /// geometry</param>
        /// <param name="fill">Overrides layers having valid fill with the given fill.</param>
        /// <param name="stroke">Ovderrides layers having valid stroke with the given stroke.</param>
        public void Render(CanvasDrawingSession session, float width, float height, Vector2 offset,
                           Vector4 padding, float rotation, ICanvasBrush fill, ICanvasStroke stroke)
        {
            for (var i = 0; i < Layers.Count(); i++)
            {
                var geometry = GetGeometry(i, width, height, offset, padding, rotation);
                if (geometry == null)
                {
                    continue;
                }

                var oldFill = GetFill(i, width, height, offset, padding, rotation);
                if (oldFill != null)
                {
                    session.FillGeometry(geometry, fill);
                }

                var oldStroke = GetStroke(i, width, height, offset, padding, rotation);
                if (oldStroke != null)
                {
                    session.DrawGeometry(geometry, stroke.Brush, stroke.Width, stroke.Style);
                }
            }
        }
 /// <summary>
 /// Draws a geometry relative to the specified position, using a CanvasStroke to define the stroke width, the stroke color and stroke style.
 /// </summary>
 /// <param name="session">CanvasDrawingSession</param>
 /// <param name="geometry">CanvasGeometry to render</param>
 /// <param name="offset">Offset</param>
 /// <param name="stroke">CanvasStroke defining the stroke width, the stroke
 /// color and stroke style.</param>
 public static void DrawGeometry(this CanvasDrawingSession session, CanvasGeometry geometry, Vector2 offset, ICanvasStroke stroke)
 {
     session.DrawGeometry(geometry, offset, stroke.Brush, stroke.Width, stroke.Style);
 }
 /// <summary>
 /// Draws an Ellipse of at the given center, having the specified radius, using a CanvasStroke to define the stroke width, the stroke color and stroke style.
 /// </summary>
 /// <param name="session">CanvasDrawingSession</param>
 /// <param name="x">Offset of the Center on the x axis</param>
 /// <param name="y">Offset of the Center on the y axis</param>
 /// <param name="radiusX">Radius in the X axis</param>
 /// <param name="radiusY">Radius in the Y axis</param>
 /// <param name="stroke">CanvasStroke defining the stroke width, the stroke
 /// color and stroke style.</param>
 public static void DrawEllipse(this CanvasDrawingSession session, float x, float y, float radiusX, float radiusY, ICanvasStroke stroke)
 {
     session.DrawEllipse(x, y, radiusX, radiusY, stroke.Brush, stroke.Width, stroke.Style);
 }
 /// <summary>
 /// Draws an Ellipse of at the given center, having the specified radius, using a CanvasStroke to define the stroke width, the stroke color and stroke style.
 /// </summary>
 /// <param name="session">CanvasDrawingSession</param>
 /// <param name="centerPoint">Center of the Circle</param>
 /// <param name="radiusX">Radius in the X axis</param>
 /// <param name="radiusY">Radius in the Y axis</param>
 /// <param name="stroke">CanvasStroke defining the stroke width, the stroke
 /// color and stroke style.</param>
 public static void DrawEllipse(this CanvasDrawingSession session, Vector2 centerPoint, float radiusX, float radiusY, ICanvasStroke stroke)
 {
     session.DrawEllipse(centerPoint, radiusX, radiusY, stroke.Brush, stroke.Width, stroke.Style);
 }
 /// <summary>
 /// Draws a Squircle of the specified dimensions, using a CanvasStroke to define the stroke width, the stroke color and stroke style.
 /// </summary>
 /// <param name="session">CanvasDrawingSession</param>
 /// <param name="x">Offset of the top left corner of the  Squircle on the x-axis</param>
 /// <param name="y">Offset of the top left corner of the  Squircle on the y-axis</param>
 /// <param name="w">Width of the  Squircle</param>
 /// <param name="h">Height of the  Squircle</param>
 /// <param name="radiusX">Corner Radius on the x axis</param>
 /// <param name="radiusY">Corner Radius on the y axis</param>
 /// <param name="offset">Offset of the Squircle from the origin.</param>
 /// <param name="stroke">CanvasStroke defining the stroke width, the stroke
 /// color and stroke style.</param>
 public static void DrawSquircle(this CanvasDrawingSession session, float x, float y, float w, float h, float radiusX, float radiusY, Vector2 offset, ICanvasStroke stroke)
 {
     using var geometry = CanvasPathGeometry.CreateSquircle(session.Device, x, y, w, h, radiusX, radiusY);
     session.DrawGeometry(geometry, offset, stroke);
 }
 /// <summary>
 /// Draws a Rounded Rectangle of the specified dimensions, using a CanvasStroke to define the stroke width, the stroke color and stroke style.
 /// </summary>
 /// <param name="session">CanvasDrawingSession</param>
 /// <param name="x">Offset of the top left corner of the  Rounded Rectangle on the x-axis</param>
 /// <param name="y">Offset of the top left corner of the  Rounded Rectangle on the y-axis</param>
 /// <param name="w">Width of the  Rounded Rectangle</param>
 /// <param name="h">Height of the  Rounded Rectangle</param>
 /// <param name="radiusX">Corner Radius on the x axis</param>
 /// <param name="radiusY">Corner Radius on the y axis</param>
 /// <param name="stroke">CanvasStroke defining the stroke width, the stroke
 /// color and stroke style.</param>
 public static void DrawRoundedRectangle(this CanvasDrawingSession session, float x, float y, float w, float h, float radiusX, float radiusY, ICanvasStroke stroke)
 {
     session.DrawRoundedRectangle(x, y, w, h, radiusX, radiusY, stroke.Brush, stroke.Width, stroke.Style);
 }
 /// <summary>
 /// Draws a Rounded Rectangle of the specified dimensions, using a CanvasStroke to define the stroke width, the stroke color and stroke style.
 /// </summary>
 /// <param name="session">CanvasDrawingSession</param>
 /// <param name="rect">Rectangle dimensions</param>
 /// <param name="radiusX">Corner Radius on the x axis</param>
 /// <param name="radiusY">Corner Radius on the y axis</param>
 /// <param name="stroke">CanvasStroke defining the stroke width, the stroke
 /// color and stroke style.</param>
 public static void DrawRoundedRectangle(this CanvasDrawingSession session, Rect rect, float radiusX, float radiusY, ICanvasStroke stroke)
 {
     session.DrawRoundedRectangle(rect, radiusX, radiusY, stroke.Brush, stroke.Width, stroke.Style);
 }
 /// <summary>
 /// Draws a Rectangle of the specified dimensions, using a CanvasStroke to define the stroke width, the stroke color and stroke style.
 /// </summary>
 /// <param name="session">CanvasDrawingSession</param>
 /// <param name="rect">Rectangle dimensions</param>
 /// <param name="stroke">CanvasStroke defining the stroke width, the stroke
 /// color and stroke style.</param>
 public static void DrawRectangle(this CanvasDrawingSession session, Rect rect, ICanvasStroke stroke)
 {
     session.DrawRectangle(rect, stroke.Brush, stroke.Width, stroke.Style);
 }
 /// <summary>
 /// Draws a line between the specified positions, using a CanvasStroke to define the stroke width, the stroke color and stroke style.
 /// </summary>
 /// <param name="session">CanvasDrawingSession</param>
 /// <param name="x0">Offset of Starting position of the line on x-axis</param>
 /// <param name="y0">Offset of Starting position of the line on y-axis</param>
 /// <param name="x1">Offset of Ending position of the line on x-axis</param>
 /// <param name="y1">Offset of Ending position of the line on y-axis</param>
 /// <param name="stroke">CanvasStroke defining the stroke width, the stroke
 /// color and stroke style.</param>
 public static void DrawLine(this CanvasDrawingSession session, float x0, float y0, float x1, float y1, ICanvasStroke stroke)
 {
     session.DrawLine(x0, y0, x1, y1, stroke.Brush, stroke.Width, stroke.Style);
 }
 /// <summary>
 /// Draws a line between the specified positions, using a CanvasStroke to define the stroke width, the stroke color and stroke style.
 /// </summary>
 /// <param name="session">CanvasDrawingSession</param>
 /// <param name="point0">Starting position of the line</param>
 /// <param name="point1">Ending position of the line</param>
 /// <param name="stroke">CanvasStroke defining the stroke width, the stroke
 /// color and stroke style.</param>
 public static void DrawLine(this CanvasDrawingSession session, Vector2 point0, Vector2 point1, ICanvasStroke stroke)
 {
     session.DrawLine(point0, point1, stroke.Brush, stroke.Width, stroke.Style);
 }
 /// <summary>
 /// Draws a geometry relative to the specified position, using a CanvasStroke to define the stroke width, the stroke color and stroke style.
 /// </summary>
 /// <param name="session">CanvasDrawingSession</param>
 /// <param name="geometry">CanvasGeometry to render</param>
 /// <param name="x">Offset on the x axis</param>
 /// <param name="y">Offset on the y axis</param>
 /// <param name="stroke">CanvasStroke defining the stroke width, the stroke
 /// color and stroke style.</param>
 public static void DrawGeometry(this CanvasDrawingSession session, CanvasGeometry geometry, float x, float y, ICanvasStroke stroke)
 {
     session.DrawGeometry(geometry, x, y, stroke.Brush, stroke.Width, stroke.Style);
 }
Exemple #25
0
 /// <summary>
 /// Creates a CanvasRenderLayer with the specified geometry, fill brush and stroke.
 /// </summary>
 /// <param name="geometry">CanvasGeometry to be rendered in this layer.</param>
 /// <param name="brush">ICanvasBrush used to fill the rendered geometry.</param>
 /// <param name="stroke">ICanvasStroke used to outline the rendered geometry.</param>
 public CanvasRenderLayer(CanvasGeometry geometry, ICanvasBrush brush, ICanvasStroke stroke)
 {
     Geometry = geometry;
     Brush    = brush;
     Stroke   = stroke;
 }
Exemple #26
0
 /// <summary>
 /// Creates a CanvasRenderLayer with the geometry, fill brush and stroke specified in
 /// string formats.
 /// </summary>
 /// <param name="creator">ICanvasResourceCreator.</param>
 /// <param name="geometryData">CanvasGeometry string definition.</param>
 /// <param name="brushData">ICanvasBrush string definition.</param>
 /// <param name="strokeData">ICanvasStroke string definition.</param>
 public CanvasRenderLayer(ICanvasResourceCreator creator, string geometryData, string brushData, string strokeData)
 {
     Geometry = String.IsNullOrWhiteSpace(geometryData) ? null : CanvasObject.CreateGeometry(creator, geometryData);
     Brush    = String.IsNullOrWhiteSpace(brushData) ? null : CanvasObject.CreateBrush(creator, brushData);
     Stroke   = String.IsNullOrWhiteSpace(strokeData) ? null : CanvasObject.CreateStroke(creator, strokeData);
 }