fix: use bool to improve performance.

This commit is contained in:
rabbitism
2023-07-31 17:32:02 +08:00
parent 0b9f920b59
commit 85f67a9c61

View File

@@ -21,6 +21,7 @@ public class ImageViewer: TemplatedControl
private VisualLayerManager? _layer; private VisualLayerManager? _layer;
private Point? _lastClickPoint; private Point? _lastClickPoint;
private Point? _lastlocation; private Point? _lastlocation;
private bool _moving;
public static readonly StyledProperty<Control?> OverlayerProperty = AvaloniaProperty.Register<ImageViewer, Control?>( public static readonly StyledProperty<Control?> OverlayerProperty = AvaloniaProperty.Register<ImageViewer, Control?>(
nameof(Overlayer)); nameof(Overlayer));
@@ -83,7 +84,7 @@ public class ImageViewer: TemplatedControl
private void OnTranslateYChanged(AvaloniaPropertyChangedEventArgs args) private void OnTranslateYChanged(AvaloniaPropertyChangedEventArgs args)
{ {
if (PseudoClasses.Contains(PC_Moving)) return; if (_moving) return;
var newValue = args.GetNewValue<double>(); var newValue = args.GetNewValue<double>();
if (_lastlocation is not null) if (_lastlocation is not null)
{ {
@@ -97,7 +98,7 @@ public class ImageViewer: TemplatedControl
private void OnTranslateXChanged(AvaloniaPropertyChangedEventArgs args) private void OnTranslateXChanged(AvaloniaPropertyChangedEventArgs args)
{ {
if (PseudoClasses.Contains(PC_Moving)) return; if (_moving) return;
var newValue = args.GetNewValue<double>(); var newValue = args.GetNewValue<double>();
if (_lastlocation is not null) if (_lastlocation is not null)
{ {
@@ -189,6 +190,7 @@ public class ImageViewer: TemplatedControl
base.OnPointerPressed(e); base.OnPointerPressed(e);
e.Pointer.Capture(this); e.Pointer.Capture(this);
_lastClickPoint = e.GetPosition(this); _lastClickPoint = e.GetPosition(this);
_moving = true;
} }
protected override void OnPointerReleased(PointerReleasedEventArgs e) protected override void OnPointerReleased(PointerReleasedEventArgs e)
@@ -197,5 +199,6 @@ public class ImageViewer: TemplatedControl
e.Pointer.Capture(null); e.Pointer.Capture(null);
_lastlocation = new Point(TranslateX, TranslateY); _lastlocation = new Point(TranslateX, TranslateY);
PseudoClasses.Set(PC_Moving, false); PseudoClasses.Set(PC_Moving, false);
_moving = false;
} }
} }