using draw command

Hi,

I’m thinkering with a component you can draw on. I was planning on using the draw command, but it’s syntax has changed since I last used it (2 years ago). Are there any working examples?

This is what I have:

protected override void OnDraw( DrawContext dc ) {
	var localToClipTransform = dc.GetLocalToClipTransform(this);

	draw
	{
		float2[] Vertices: new [] { float2(0), float2(1) };

		float2 Coord: vertex_attrib(Vertices);
		ClipPosition : Vector.Transform(float4(Coord, 0, 1), localToClipTransform);

		PixelColor: float4(1,0,0,1);
		LineWidth : 4f;

		PrimitiveType: Uno.Graphics.PrimitiveType.Lines;
	};	
}

I thought this would give a straight red line across the panel.

This is a simple control that draws a gradient with a blue highlight wherever the user presses the pointer.

This code is however not supported, and the actual APIs involved are subject to change.

using Uno;

using Fuse;
using Fuse.Input;
using Fuse.Controls;

public class MyControl : Control
{
	protected override void OnRooted()
	{
		base.OnRooted();
		Pointer.Pressed.AddHandler(this, OnPressed);
	}
	
	protected override void OnUnrooted()
	{
		Pointer.Pressed.RemoveHandler(this, OnPressed);
		base.OnUnrooted();
	}

	float2 _center;
	
	void OnPressed(object sender, PointerPressedArgs args)
	{
		_center = WindowToLocal(args.WindowPoint);
		InvalidateVisual();
	}
	
	protected override void DrawVisual(DrawContext dc)
	{
		var c = _center / ActualSize;
		draw Fuse.Drawing.Planar.Rectangle
		{
			DrawContext: dc;
			Visual: this;
			Position: float2(0);
			Size: ActualSize;
			float distance: Math.Pow(1-Vector.Length(pixel VertexPosition2 - c),3);
			PixelColor: float4(VertexPosition2,distance,1);
		};
	}
	
	protected override VisualBounds HitTestLocalVisualBounds
	{
		get
		{
			var nb = base.HitTestLocalVisualBounds;
			nb = nb.AddRect( float2(0), ActualSize );
			return nb;
		}
	}
	
	protected override void OnHitTestLocalVisual(HitTestContext htc)
	{
		if (IsPointInside(htc.LocalPoint))
			htc.Hit(this);

		base.OnHitTestLocalVisual(htc);
	}

	protected override VisualBounds CalcRenderBounds()
	{
		var b = base.CalcRenderBounds();
		b = b.AddRect( float2(0), ActualSize );
		return b;
	}
}
<App>
	<MyControl Alignment="Center" Width="300" Height="300"/>
</App>