Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/fpgarework' into fpgarework
Browse files Browse the repository at this point in the history
  • Loading branch information
HendrikMennen committed Aug 5, 2024
2 parents 835ffa0 + 7a6975c commit 69a34e0
Showing 1 changed file with 24 additions and 12 deletions.
36 changes: 24 additions & 12 deletions src/OneWare.Essentials/Controls/CustomZoomBorder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using Avalonia;
using Avalonia.Controls.PanAndZoom;
using Avalonia.Input;
using Avalonia.Interactivity;
using Avalonia.ReactiveUI;
using Avalonia.Threading;

Expand All @@ -21,19 +22,12 @@ public class CustomZoomBorder : ZoomBorder
protected override void OnAttachedToVisualTree(VisualTreeAttachmentEventArgs e)
{
base.OnAttachedToVisualTree(e);

Observable.FromEventPattern<KeyEventArgs>(this, nameof(KeyDown))
.ObserveOn(AvaloniaScheduler.Instance).Subscribe(x =>
{
_keysDown.Add(x.EventArgs.Key);
}).DisposeWith(_disposables);

Observable.FromEventPattern<KeyEventArgs>(this, nameof(KeyUp))
.ObserveOn(AvaloniaScheduler.Instance).Subscribe(x =>
{
_keysDown.Remove(x.EventArgs.Key);
}).DisposeWith(_disposables);

PointerEntered += (_, _) =>
{
this.Focus();
};

DispatcherTimer.Run(() =>
{
if (_keysDown.Contains(Key.Down) || _keysDown.Contains(Key.S))
Expand All @@ -56,4 +50,22 @@ protected override void OnDetachedFromVisualTree(VisualTreeAttachmentEventArgs e
_disposables.Dispose();
_disposables = new CompositeDisposable();
}

protected override void OnKeyDown(KeyEventArgs e)
{
_keysDown.Add(e.Key);
base.OnKeyDown(e);
}

protected override void OnKeyUp(KeyEventArgs e)
{
_keysDown.RemoveAll(x => x == e.Key);
base.OnKeyUp(e);
}

protected override void OnLostFocus(RoutedEventArgs e)
{
_keysDown.Clear();
base.OnLostFocus(e);
}
}

0 comments on commit 69a34e0

Please sign in to comment.