diff --git a/samples/SkiaSharpDemo/App.xaml b/samples/SkiaSharpDemo/App.xaml index 96137544..dcc70754 100644 --- a/samples/SkiaSharpDemo/App.xaml +++ b/samples/SkiaSharpDemo/App.xaml @@ -5,6 +5,9 @@ x:Class="SkiaSharpDemo.App"> + + + @@ -19,6 +22,38 @@ + + + + + diff --git a/samples/SkiaSharpDemo/App.xaml.cs b/samples/SkiaSharpDemo/App.xaml.cs index e93e424b..6da48107 100644 --- a/samples/SkiaSharpDemo/App.xaml.cs +++ b/samples/SkiaSharpDemo/App.xaml.cs @@ -12,6 +12,8 @@ public partial class App : Application { public App() { + Device.SetFlags(new[] { "CarouselView_Experimental" }); + InitializeComponent(); // register the default fonts that we want for Iconify diff --git a/samples/SkiaSharpDemo/Demos/Confetti/ConfettiConfig.cs b/samples/SkiaSharpDemo/Demos/Confetti/ConfettiConfig.cs new file mode 100644 index 00000000..02b07c61 --- /dev/null +++ b/samples/SkiaSharpDemo/Demos/Confetti/ConfettiConfig.cs @@ -0,0 +1,121 @@ +using System; +using System.Collections.Generic; +using System.Collections.ObjectModel; +using System.Linq; +using SkiaSharp; +using SkiaSharp.Extended.UI.Controls; +using Xamarin.Forms; + +namespace SkiaSharpDemo.Demos +{ + public class ConfettiConfig : BindableObject + { + private static readonly SKPath heartGeometry = SKPath.ParseSvgPathData("M 311.92745,171.20458 170.5061,312.62594 29.08474,171.20458 A 100,100 0 0 1 170.5061,29.783225 100,100 0 0 1 311.92745,171.20458 Z"); + + private int minSpeed = 100; + private int maxSpeed = 200; + private double lifetime = 2; + private double duration = 5; + + public ConfettiConfig(int numberOfSystems = 1) + { + NumberOfSystems = numberOfSystems; + } + + public int NumberOfSystems { get; } + + public int MinSpeed + { + get => minSpeed; + set + { + minSpeed = value; + OnPropertyChanged(); + } + } + + public int MaxSpeed + { + get => maxSpeed; + set + { + maxSpeed = value; + OnPropertyChanged(); + } + } + + public double Lifetime + { + get => lifetime; + set + { + lifetime = value; + OnPropertyChanged(); + } + } + + public double Duration + { + get => duration; + set + { + duration = value; + OnPropertyChanged(); + } + } + + public ObservableCollection Shapes { get; } = new ObservableCollection + { + "Square", + "Circle", + "Line", + }; + + public ObservableCollection Colors { get; } = new ObservableCollection + { + Color.FromUint(0xfffce18a), + Color.FromUint(0xffff726d), + Color.FromUint(0xfff4306d), + Color.FromUint(0xffb48def), + }; + + public Action? OnCreateSystem { get; set; } + + public IEnumerable CreateSystems() + { + for (var i = 0; i < NumberOfSystems; i++) + { + var system = new SKConfettiSystem + { + Lifetime = Lifetime, + Emitter = SKConfettiEmitter.Stream(100, Duration), + EmitterBounds = SKConfettiEmitterBounds.Top, + Colors = new SKConfettiColorCollection(Colors), + Shapes = new SKConfettiShapeCollection(GetShapes(Shapes).SelectMany(s => s)), + MinimumInitialVelocity = MinSpeed, + MaximumInitialVelocity = MaxSpeed, + }; + + OnCreateSystem?.Invoke(i, system); + + yield return system; + } + } + + private static IEnumerable> GetShapes(IEnumerable shapes) + { + foreach (var shape in shapes) + { + yield return shape.ToLowerInvariant() switch + { + "square" => new SKConfettiShape[] { new SKConfettiSquareShape(), new SKConfettiRectShape(0.5) }, + "circle" => new SKConfettiShape[] { new SKConfettiCircleShape(), new SKConfettiOvalShape(0.5) }, + "line" => new[] { new SKConfettiRectShape(0.1) }, + "heart" => new[] { new SKConfettiPathShape(heartGeometry) }, + "star" => new[] { new ConfettiStar(5) }, + _ => throw new ArgumentOutOfRangeException(nameof(shape)), + }; + } + } + } +} diff --git a/samples/SkiaSharpDemo/Demos/Confetti/ConfettiPage.xaml b/samples/SkiaSharpDemo/Demos/Confetti/ConfettiPage.xaml new file mode 100644 index 00000000..0e129bc4 --- /dev/null +++ b/samples/SkiaSharpDemo/Demos/Confetti/ConfettiPage.xaml @@ -0,0 +1,157 @@ + + + + +