Skip to content

Instantly share code, notes, and snippets.

@grokys
Created September 4, 2020 12:31
Show Gist options
  • Save grokys/b4c440986454013d8d9b676eb223e028 to your computer and use it in GitHub Desktop.
Save grokys/b4c440986454013d8d9b676eb223e028 to your computer and use it in GitHub Desktop.
using Avalonia;
using Avalonia.Controls;
using Avalonia.Controls.Shapes;
using Avalonia.Input;
using Avalonia.Markup.Xaml;
using Avalonia.Media;
namespace LotsaPaths
{
public class MainWindow : Window
{
private readonly Canvas canvas;
private double zoom = 1;
public MainWindow()
{
InitializeComponent();
canvas = new Canvas();
for (var i = 0; i < 1024; ++i)
{
var path = new Path
{
Data = StreamGeometry.Parse(@"M 320.000 340.000
L 340.000 354.641
L 337.321 330.000
L 360.000 320.000
L 337.321 310.000
L 340.000 285.359
L 320.000 300.000
L 300.000 285.359
L 302.679 310.000
L 280.000 320.000
L 302.679 330.000
L 300.000 354.641
z"),
Stroke = Brushes.Black,
StrokeThickness = 2,
Width = 32,
Height = 32,
Stretch = Stretch.Fill,
};
canvas.Children.Add(path);
Canvas.SetLeft(path, (i % 32) * 32);
Canvas.SetTop(path, ((int)(i / 32)) * 32);
}
Content = canvas;
}
protected override void OnPointerWheelChanged(PointerWheelEventArgs e)
{
base.OnPointerWheelChanged(e);
if (canvas.RenderTransform is null)
{
canvas.RenderTransform = new ScaleTransform();
}
zoom += e.Delta.Y / 8;
var t = (ScaleTransform)canvas.RenderTransform;
t.ScaleX = t.ScaleY = zoom;
}
private void InitializeComponent()
{
AvaloniaXamlLoader.Load(this);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment