/// <summary>
 /// Redraws the GeometrySurface by filling the existing geometry with
 /// the foreground color.
 /// </summary>
 /// <param name="fillColor">Color with which the GeometrySurface geometry is to be filled</param>
 public void Redraw(Color fillColor)
 {
     // Set the fill
     _fill = new CanvasSolidColorBrush(_generator.Device, fillColor);
     // Redraw the GeometrySurface
     RedrawSurfaceInternal();
 }
예제 #2
0
 /// <summary>
 /// Resizes the GeometrySurface with the given size and redraws the GeometrySurface
 /// with the new geometry and fills it with the foreground color and
 /// fills the background with the background 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="fillColor">Fill color for the geometry</param>
 /// <param name="backgroundColor">Fill color for the GeometrySurface background</param>
 public void Redraw(Size size, CanvasGeometry geometry, Color fillColor, Color backgroundColor)
 {
     // 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 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();
 }
예제 #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();
 }
예제 #4
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();
 }
예제 #5
0
        private void _patternRender(ICanvasResourceCreator resourceCreator, CanvasDrawingSession drawingSession, CanvasGeometry geometry)
        {
            switch (base.Style.Transparency.Type)
            {
            case BrushType.LinearGradient:
            case BrushType.RadialGradient:
            case BrushType.EllipticalGradient:
            {
                ICanvasBrush canvasBrush = this.Style.Transparency.GetICanvasBrush(resourceCreator);

                using (drawingSession.CreateLayer(canvasBrush, geometry))
                {
                    this._render(resourceCreator, drawingSession, geometry);
                }
            }
            break;

            default:
                using (drawingSession.CreateLayer(1, geometry))
                {
                    this._render(resourceCreator, drawingSession, geometry);
                }
                break;
            }
        }
예제 #6
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);
 }
 /// <summary>
 /// Redraws the GeometrySurface by filling the existing geometry with
 /// the foreground color.
 /// </summary>
 /// <param name="foregroundColor">Color with which the GeometrySurface geometry is to be filled</param>
 public void Redraw(Color foregroundColor)
 {
     // Set the foregroundBrush
     _foregroundBrush = new CanvasSolidColorBrush(_generator.Device, foregroundColor);
     // Redraw the GeometrySurface
     RedrawSurfaceInternal();
 }
예제 #8
0
        public CircleTextRenderer(Vector2 Origin, float[] TextWidths, ICanvasBrush Brush)
        {
            this.Origin     = Origin;
            this.TextWidths = TextWidths;
            this.Brush      = Brush;

            PTextW = TextWidths[0];
        }
 public override ICanvasBrush Apply(BitmapCanvas dst, ICanvasBrush brush)
 {
     //var originalColor = Colors.White;
     //if (brush is CompositionColorBrush compositionColorBrush)
     //    originalColor = compositionColorBrush.Color;
     //TODO
     return(brush);
 }
예제 #10
0
 public void DestroyResources()
 {
     if (_brush != null)
     {
         _brush.Dispose();
         _brush = null;
     }
 }
예제 #11
0
        public static ITextStrategy TextNoOutline(
            ICanvasBrush brushText)
        {
            TextNoOutlineStrategy strat = new TextNoOutlineStrategy();

            strat.Init(brushText);

            return(strat);
        }
 /// <summary>
 /// Redraws the GeometrySurface by filling the existing geometry with
 /// the foreground brush and the background with the background brush.
 /// </summary>
 /// <param name="foregroundBrush">Brush with which the GeometrySurface geometry is to be filled</param>
 /// <param name="backgroundColor">Color with which the GeometrySurface background is to be filled</param>
 public void Redraw(ICanvasBrush foregroundBrush, Color backgroundColor)
 {
     // Set the foregroundBrush
     _foregroundBrush = foregroundBrush ?? new CanvasSolidColorBrush(_generator.Device, Colors.Transparent);
     // Set the backgroundBrush
     _backgroundBrush = new CanvasSolidColorBrush(_generator.Device, backgroundColor);
     // 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
     RedrawSurface();
 }
예제 #14
0
        public static ITextStrategy TextOutline(
            ICanvasBrush brushText,
            Color clrOutline,
            int nThickness)
        {
            TextOutlineStrategy strat = new TextOutlineStrategy();

            strat.Init(brushText, clrOutline, nThickness);

            return(strat);
        }
        /// <summary>
        /// Creates a GeometrySurface having the given size, geometry, foreground brush and
        /// background brush with MaskMode as False.
        /// </summary>
        /// <param name="size">Size of the mask</param>
        /// <param name="geometry">Geometry of the mask</param>
        /// <param name="foregroundBrush">The brush with which the geometry has to be filled</param>
        /// <param name="backgroundBrush">The brush to fill the Mask background surface which is
        /// not covered by the geometry</param>
        /// <returns>IGeometrySurface</returns>
        public IGeometrySurface CreateGeometrySurface(Size size, CanvasGeometry geometry, ICanvasBrush foregroundBrush,
                                                      ICanvasBrush backgroundBrush)
        {
            // Initialize the mask
            IGeometrySurface mask = new GeometrySurface(this, size, geometry, foregroundBrush, backgroundBrush);

            // Render the mask
            mask.Redraw();

            return(mask);
        }
        /// <summary>
        /// Creates a GeometrySurface having the given size, geometry, foreground color and
        /// background brush with MaskMode as False.
        /// </summary>
        /// <param name="size">Size of the mask</param>
        /// <param name="geometry">Geometry of the mask</param>
        /// <param name="foregroundColor">Fill color of the geometry</param>
        /// <param name="backgroundBrush">The brush to fill the Mask background surface which is
        /// not covered by the geometry</param>
        /// <returns>IGeometrySurface</returns>
        public IGeometrySurface CreateGeometrySurface(Size size, CanvasGeometry geometry, Color foregroundColor,
                                                      ICanvasBrush backgroundBrush)
        {
            // Create the foreground brush
            var foregroundBrush = new CanvasSolidColorBrush(Device, foregroundColor);
            // Initialize the mask
            IGeometrySurface mask = new GeometrySurface(this, size, geometry, foregroundBrush, backgroundBrush);

            // Render the mask
            mask.Redraw();

            return(mask);
        }
예제 #17
0
        public static ITextStrategy TextGradOutline(
            ICanvasBrush brushText,
            Color clrOutline1,
            Color clrOutline2,
            int nThickness,
            GradientType gradType)
        {
            TextGradOutlineStrategy strat = new TextGradOutlineStrategy();

            strat.Init(brushText, clrOutline1, clrOutline2, nThickness, gradType);

            return(strat);
        }
 /// <summary>
 /// Redraws the GeometrySurface by filling the existing geometry with
 /// the foreground brush and the background with the background brush.
 /// </summary>
 /// <param name="foregroundBrush">Brush with which the GeometrySurface geometry is to be filled</param>
 /// <param name="backgroundColor">Color with which the GeometrySurface background is to be filled</param>
 public void Redraw(ICanvasBrush foregroundBrush, Color backgroundColor)
 {
     // Set the foregroundBrush
     _foregroundBrush = foregroundBrush ?? new CanvasSolidColorBrush(_generator.Device, Colors.Transparent);
     // Set the backgroundBrush
     _backgroundBrush = new CanvasSolidColorBrush(_generator.Device, backgroundColor);
     // Redraw the GeometrySurface
     RedrawSurfaceInternal();
 }
예제 #19
0
		private void CanvasAnimatedControl_OnCreateResources(CanvasAnimatedControl sender, CanvasCreateResourcesEventArgs args)
		{
			//guides
			_center = new Vector2((float)(sender.Size.Width / 2.0), (float)(sender.Size.Height / 2.0f));
			_size = (float) Math.Min(sender.Size.Height, sender.Size.Width);
			_half = _size / 2.0f;
			_ringCount = Convert.ToInt32(Math.Floor((_half - (StartOffset + EndOffset))/(RingPadding + RingStrokeWidth)));
			var nudge = _size * 0.174f;

			//mask
			var crt = new CanvasRenderTarget(sender, _size, _size, sender.Dpi);
			using (var session = crt.CreateDrawingSession())
			{
				session.Clear(new Vector4(0, 0, 0, 0));
				var pa = new CanvasGradientMeshPatch[4];
				pa[0] = CanvasGradientMesh.CreateCoonsPatch(
					new[]
					{
						new Vector2(_half, 0.0f), //center top
						new Vector2(_half, 0.0f), //center top
						new Vector2(_size, 0.0f), //right top
						new Vector2(_size, _half), //right middle
						new Vector2(_half-nudge, _half), //center middle (nudged left)
						new Vector2(_half-nudge, _half), //center middle (nudged left)
						new Vector2(_size, _half), //right middle
						new Vector2(_size, _size), //right bottom
						new Vector2(_half, _size), //center bottom
						new Vector2(_half, _size), //center bottom
						new Vector2(-nudge, _size), //left bottom (nudged left)
						new Vector2(-nudge, 0.0f), //left top (nudged left)
					},
					new[]
					{
						new Vector4(1, 1, 1, 1), new Vector4(1, 1, 1, 1),
						new Vector4(0, 0, 0, 0), new Vector4(0, 0, 0, 0),
					},
					new[]
					{
						CanvasGradientMeshPatchEdge.Antialiased, CanvasGradientMeshPatchEdge.Antialiased,
						CanvasGradientMeshPatchEdge.Antialiased, CanvasGradientMeshPatchEdge.Antialiased
					});

				var gm = new CanvasGradientMesh(session, pa);
				session.DrawGradientMesh(gm);
			}
			var ib = new CanvasImageBrush(sender, crt);
			_brush = ib;

			//animation pattern
			_pattern = new List<double>();
			for (int i = 0; i < 3; i++)
			{
				for (int j = 0; j < _ringCount; j++)
				{
					_pattern.Add(0.0);
				}
			}
			for (int i = 0; i < _ringCount; i++)
			{
				_pattern.Add((1.0/_ringCount)*(i + 1));
			}
			for (int i = _ringCount - 1; i > 0; i--)
			{
				_pattern.Add((1.0 / _ringCount) * (i));
			}
			for (int j = 0; j < _ringCount; j++)
			{
				_pattern.Add(0.0);
			}
		}
예제 #20
0
	    private void CanvasAnimatedControl_OnCreateResources(CanvasAnimatedControl sender, CanvasCreateResourcesEventArgs args)
	    {
			// blobs
			_blobs = new List<Blob>();
			var rnd = new Random();
		    for (int i = 0; i < BlobCount; i++)
		    {
			    _blobs.Add(new Blob
			    {
				    Position = new Vector2((float) (rnd.NextDouble()*sender.Size.Width), (float) (rnd.NextDouble()*sender.Size.Height)),
				    Velocity = new Vector2(BlobVelocityScale *  (float) ((rnd.NextDouble()*3.0f) - 1.5f), BlobVelocityScale * (float) ((rnd.NextDouble()*3.0f) - 1.5f))
			    });
		    }
			// texture
		    var rgb = new CanvasRadialGradientBrush(sender, new[]
		    {
				new CanvasGradientStop
				{
					Color = Color.FromArgb(255, 128, 128, 255),
					Position = 0.0f
				},
				new CanvasGradientStop
				{
					Color = Color.FromArgb(128, 128, 128, 255),
					Position = 0.6f
				},
				new CanvasGradientStop
				{
					Color = Color.FromArgb(0, 128, 128, 255),
					Position = 1.0f
				}
		    });
		    rgb.RadiusX = rgb.RadiusY = BlobSize;
		    _blobBrush = rgb;
			// table transfer table
			ttt = new List<float>();
			for (int i = 0; i < 100; i++)
			{
				ttt.Add(i < Threshold ? 0.0f : 1.0f);
			}
			// setup
			_blobRenderTarget = new CanvasRenderTarget(sender, sender.Size);
			_pre = new PremultiplyEffect {Source = _blobRenderTarget};
			_tte = new TableTransferEffect {ClampOutput = true, Source = _pre};
			_tte.AlphaTable = _tte.RedTable = _tte.GreenTable = _tte.BlueTable = ttt.ToArray();
			_un = new UnPremultiplyEffect {Source = _tte};
			_gbe = new GaussianBlurEffect {BlurAmount = 8.0f, Source = _un};
		    _mask = new CanvasImageBrush(sender) {SourceRectangle = new Rect(new Point(), sender.Size)};
	    }
 /// <summary>
 /// Redraws the GeometrySurface by filling the existing geometry with
 /// the foreground color and the background with the background color. 
 /// </summary>
 /// <param name="foregroundColor">Color with which the GeometrySurface geometry is to be filled</param>
 /// <param name="backgroundColor">Color with which the GeometrySurface background is to be filled</param>
 public void Redraw(Color foregroundColor, Color backgroundColor)
 {
     // Set the foregroundBrush
     _foregroundBrush = new CanvasSolidColorBrush(_generator.Device, foregroundColor);
     // Set the backgroundBrush
     _backgroundBrush = new CanvasSolidColorBrush(_generator.Device, backgroundColor);
     // Redraw the GeometrySurface
     RedrawSurfaceInternal();
 }
        /// <summary>
        /// Creates a GeometrySurface having the given size, geometry, foreground color and
        /// background brush with MaskMode as False.
        /// </summary>
        /// <param name="size">Size of the mask</param>
        /// <param name="geometry">Geometry of the mask</param>
        /// <param name="foregroundColor">Fill color of the geometry</param>
        /// <param name="backgroundBrush">The brush to fill the Mask background surface which is 
        /// not covered by the geometry</param>
        /// <returns>IGeometrySurface</returns>
        public IGeometrySurface CreateGeometrySurface(Size size, CanvasGeometry geometry, Color foregroundColor,
            ICanvasBrush backgroundBrush)
        {
            // Create the foreground brush
            var foregroundBrush = new CanvasSolidColorBrush(Device, foregroundColor);
            // Initialize the mask
            IGeometrySurface mask = new GeometrySurface(this, size, geometry, foregroundBrush, backgroundBrush);

            // Render the mask
            mask.Redraw();

            return mask;
        }
        /// <summary>
        /// Creates a GeometrySurface having the given size, geometry, foreground brush and
        /// background brush with MaskMode as False.
        /// </summary>
        /// <param name="size">Size of the mask</param>
        /// <param name="geometry">Geometry of the mask</param>
        /// <param name="foregroundBrush">The brush with which the geometry has to be filled</param>
        /// <param name="backgroundBrush">The brush to fill the Mask background surface which is 
        /// not covered by the geometry</param>
        /// <returns>IGeometrySurface</returns>
        public IGeometrySurface CreateGeometrySurface(Size size, CanvasGeometry geometry, ICanvasBrush foregroundBrush,
            ICanvasBrush backgroundBrush)
        {
            // Initialize the mask
            IGeometrySurface mask = new GeometrySurface(this, size, geometry, foregroundBrush, backgroundBrush);
            // Render the mask
            mask.Redraw();

            return mask;
        }
 /// <summary>
 /// Resizes the GeometrySurface with the given size and redraws the GeometrySurface
 /// with the new geometry and fills it with the foreground 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="foregroundColor">Fill color for the geometry</param>
 /// <param name="backgroundBrush">Brush to fill the GeometrySurface background</param>
 public void Redraw(Size size, CanvasGeometry geometry, Color foregroundColor,
     ICanvasBrush backgroundBrush)
 {
     _generator.ResizeDrawingSurface(_surfaceLock, _surface, size);
     // Set the size
     Size = _surface?.Size ?? new Size(0, 0);
     // Set the new geometry
     _geometry = geometry;
     // Set the foregroundBrush
     _foregroundBrush = new CanvasSolidColorBrush(_generator.Device, foregroundColor);
     // Set the backgroundBrush
     _backgroundBrush = backgroundBrush ?? new CanvasSolidColorBrush(_generator.Device, Colors.Transparent);
     // Redraw the GeometrySurface
     RedrawSurfaceInternal();
 }
        /// <summary>
        /// Redraws the GeometrySurface with the given size, geometry, foreground brush and background brush
        /// </summary>
        /// <param name="surfaceLock">The object to lock to prevent multiple threads
        /// from accessing the surface at the same time.</param>
        /// <param name="surface">CompositionDrawingSurface</param>
        /// <param name="size">Size ofthe GeometrySurface</param>
        /// <param name="geometry">Geometry of the GeometrySurface</param>
        /// <param name="foregroundBrush">The brush with which the geometry has to be filled</param>
        /// <param name="backgroundBrush">The brush with which the GeometrySurface background has to be filled</param>
        public void RedrawGeometrySurface(object surfaceLock, CompositionDrawingSurface surface, Size size,
            CanvasGeometry geometry, ICanvasBrush foregroundBrush, ICanvasBrush backgroundBrush)
        {
            // If the surface is not created, create it
            if (surface == null)
            {
                surface = CreateDrawingSurface(surfaceLock, size);
            }

            // No need to render if the width and/or height of the surface is zero
            if (surface.Size.Width.IsZero() || surface.Size.Height.IsZero())
                return;

            //
            // Since multiple threads could be trying to get access to the device/surface 
            // at the same time, we need to do any device/surface work under a lock.
            //
            lock (surfaceLock)
            {
                // Render the mask to the surface
                using (var session = CanvasComposition.CreateDrawingSession(surface))
                {
                    // First fill the background
                    var brush = backgroundBrush as CanvasSolidColorBrush;
                    if (brush != null)
                    {
                        // If the backgroundBrush is a SolideColorBrush then use the Clear()
                        // method to fill the surface with background color. It is faster.
                        // Clear the surface with the background color
                        session.Clear(brush.Color);
                    }
                    else
                    {
                        // Fill the surface with the background brush.
                        session.FillRectangle(0, 0, size.Width.Single(), size.Height.Single(), backgroundBrush);
                    }

                    // If the geometry is not null then fill the geometry area with the foreground brush.
                    if (geometry != null)
                    {
                        session.FillGeometry(geometry, foregroundBrush);
                    }
                }
            }
        }
        /// <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="foregroundColor">Fill color of the geometry</param>
        /// <param name="backgroundColor">Brush to fill the GeometrySurface background surface which is 
        /// not covered by the geometry</param>
        public GeometrySurface(ICompositionGeneratorInternal generator, Size size, CanvasGeometry geometry,
            Color foregroundColor, Color backgroundColor)
        {
            if (generator == null)
                throw new ArgumentNullException(nameof(generator), "CompositionGenerator cannot be null!");

            _generator = generator;
            _surfaceLock = new object();
            _geometry = geometry;
            _foregroundBrush = new CanvasSolidColorBrush(_generator.Device, foregroundColor);
            _backgroundBrush = new CanvasSolidColorBrush(_generator.Device, backgroundColor);

            // Create GeometrySurface
            _surface = _generator.CreateDrawingSurface(_surfaceLock, size);
            // Set the size
            Size = _surface?.Size ?? new Size(0, 0);
            // Subscribe to DeviceReplaced event
            _generator.DeviceReplaced += OnDeviceReplaced;
        }