MainWindow.xaml.cs 3.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. // Copyright (c) The Avalonia Project. All rights reserved.
  2. // Licensed under the MIT license. See licence.md file in the project root for full license information.
  3. using System;
  4. using System.Reactive.Linq;
  5. using Avalonia;
  6. using Avalonia.Animation;
  7. using Avalonia.Controls;
  8. using Avalonia.Controls.Shapes;
  9. using Avalonia.Data;
  10. using Avalonia.Layout;
  11. using Avalonia.Markup.Xaml;
  12. using Avalonia.Media;
  13. using Avalonia.Rendering;
  14. namespace RenderTest
  15. {
  16. public class MainWindow : Window
  17. {
  18. public MainWindow()
  19. {
  20. this.InitializeComponent();
  21. this.CreateAnimations();
  22. this.AttachDevTools();
  23. Renderer.DrawFps = true;
  24. }
  25. private void InitializeComponent()
  26. {
  27. AvaloniaXamlLoader.Load(this);
  28. }
  29. private void CreateAnimations()
  30. {
  31. const int Count = 100;
  32. var panel = new WrapPanel();
  33. for (var i = 0; i < Count; ++i)
  34. {
  35. var element = new Panel
  36. {
  37. Children =
  38. {
  39. new Ellipse
  40. {
  41. Width = 100,
  42. Height = 100,
  43. Fill = Brushes.Blue,
  44. },
  45. new Path
  46. {
  47. Data = StreamGeometry.Parse(
  48. "F1 M 16.6309,18.6563C 17.1309,8.15625 29.8809,14.1563 29.8809,14.1563C 30.8809,11.1563 34.1308,11.4063 34.1308,11.4063C 33.5,12 34.6309,13.1563 34.6309,13.1563C 32.1309,13.1562 31.1309,14.9062 31.1309,14.9062C 41.1309,23.9062 32.6309,27.9063 32.6309,27.9062C 24.6309,24.9063 21.1309,22.1562 16.6309,18.6563 Z M 16.6309,19.9063C 21.6309,24.1563 25.1309,26.1562 31.6309,28.6562C 31.6309,28.6562 26.3809,39.1562 18.3809,36.1563C 18.3809,36.1563 18,38 16.3809,36.9063C 15,36 16.3809,34.9063 16.3809,34.9063C 16.3809,34.9063 10.1309,30.9062 16.6309,19.9063 Z"),
  49. Fill = Brushes.Green,
  50. HorizontalAlignment = HorizontalAlignment.Center,
  51. VerticalAlignment = VerticalAlignment.Center,
  52. RenderTransform = new ScaleTransform(2, 2),
  53. }
  54. },
  55. Margin = new Thickness(4),
  56. RenderTransform = new ScaleTransform(),
  57. };
  58. var start = Animate.Stopwatch.Elapsed;
  59. var index = i;
  60. var degrees = Animate.Timer
  61. .Select(x => (x - start).TotalSeconds)
  62. .Where(x => (x % Count) >= index && (x % Count) < index + 1)
  63. .Select(x => (x % 1) / 1);
  64. element.RenderTransform.Bind(
  65. ScaleTransform.ScaleXProperty,
  66. degrees,
  67. BindingPriority.Animation);
  68. panel.Children.Add(element);
  69. }
  70. Content = panel;
  71. }
  72. }
  73. }