GpuDemo.axaml.cs 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. using Avalonia;
  2. using Avalonia.Controls;
  3. using Avalonia.Markup.Xaml;
  4. namespace GpuInterop;
  5. public class GpuDemo : UserControl
  6. {
  7. public GpuDemo()
  8. {
  9. AvaloniaXamlLoader.Load(this);
  10. }
  11. private float _yaw = 5;
  12. public static readonly DirectProperty<GpuDemo, float> YawProperty =
  13. AvaloniaProperty.RegisterDirect<GpuDemo, float>("Yaw", o => o.Yaw, (o, v) => o.Yaw = v);
  14. public float Yaw
  15. {
  16. get => _yaw;
  17. set => SetAndRaise(YawProperty, ref _yaw, value);
  18. }
  19. private float _pitch = 5;
  20. public static readonly DirectProperty<GpuDemo, float> PitchProperty =
  21. AvaloniaProperty.RegisterDirect<GpuDemo, float>("Pitch", o => o.Pitch, (o, v) => o.Pitch = v);
  22. public float Pitch
  23. {
  24. get => _pitch;
  25. set => SetAndRaise(PitchProperty, ref _pitch, value);
  26. }
  27. private float _roll = 5;
  28. public static readonly DirectProperty<GpuDemo, float> RollProperty =
  29. AvaloniaProperty.RegisterDirect<GpuDemo, float>("Roll", o => o.Roll, (o, v) => o.Roll = v);
  30. public float Roll
  31. {
  32. get => _roll;
  33. set => SetAndRaise(RollProperty, ref _roll, value);
  34. }
  35. private float _disco;
  36. public static readonly DirectProperty<GpuDemo, float> DiscoProperty =
  37. AvaloniaProperty.RegisterDirect<GpuDemo, float>("Disco", o => o.Disco, (o, v) => o.Disco = v);
  38. public float Disco
  39. {
  40. get => _disco;
  41. set => SetAndRaise(DiscoProperty, ref _disco, value);
  42. }
  43. private string _info = string.Empty;
  44. public static readonly DirectProperty<GpuDemo, string> InfoProperty =
  45. AvaloniaProperty.RegisterDirect<GpuDemo, string>("Info", o => o.Info, (o, v) => o.Info = v);
  46. public string Info
  47. {
  48. get => _info;
  49. set => SetAndRaise(InfoProperty, ref _info, value);
  50. }
  51. private bool _discoVisible;
  52. public static readonly DirectProperty<GpuDemo, bool> DiscoVisibleProperty =
  53. AvaloniaProperty.RegisterDirect<GpuDemo, bool>("DiscoVisible", o => o.DiscoVisible,
  54. (o, v) => o._discoVisible = v);
  55. public bool DiscoVisible
  56. {
  57. get => _discoVisible;
  58. set => SetAndRaise(DiscoVisibleProperty, ref _discoVisible, value);
  59. }
  60. private IGpuDemo? _demo;
  61. public static readonly DirectProperty<GpuDemo, IGpuDemo?> DemoProperty =
  62. AvaloniaProperty.RegisterDirect<GpuDemo, IGpuDemo?>("Demo", o => o.Demo,
  63. (o, v) => o._demo = v);
  64. public IGpuDemo? Demo
  65. {
  66. get => _demo;
  67. set => SetAndRaise(DemoProperty, ref _demo, value);
  68. }
  69. protected override void OnPropertyChanged(AvaloniaPropertyChangedEventArgs change)
  70. {
  71. if (change.Property == YawProperty
  72. || change.Property == PitchProperty
  73. || change.Property == RollProperty
  74. || change.Property == DiscoProperty
  75. || change.Property == DemoProperty
  76. )
  77. {
  78. if (change.Property == DemoProperty)
  79. ((IGpuDemo?)change.OldValue)?.Update(null, 0, 0, 0, 0);
  80. _demo?.Update(this, Yaw, Pitch, Roll, Disco);
  81. }
  82. base.OnPropertyChanged(change);
  83. }
  84. }
  85. public interface IGpuDemo
  86. {
  87. void Update(GpuDemo? parent, float yaw, float pitch, float roll, float disco);
  88. }