Browse Source

Prevent setting the cursor to often.

pull/1417/head
boombuler 9 years ago
parent
commit
cfb3924c0f
  1. 33
      src/Avalonia.Controls/DragDrop/DragSource.cs

33
src/Avalonia.Controls/DragDrop/DragSource.cs

@ -25,7 +25,8 @@ namespace Avalonia.Controls.DragDrop
private IDataObject _draggedData; private IDataObject _draggedData;
private IInputElement _lastRoot; private IInputElement _lastRoot;
private Point _lastPosition; private Point _lastPosition;
private object _lastCursor; private StandardCursorType _lastCursorType;
private object _originalCursor;
private InputModifiers? _initialInputModifiers; private InputModifiers? _initialInputModifiers;
public DragSource() public DragSource()
@ -81,15 +82,15 @@ namespace Avalonia.Controls.DragDrop
return DragDropEffects.Move; return DragDropEffects.Move;
} }
private Cursor GetCursorForDropEffect(DragDropEffects effects) private StandardCursorType GetCursorForDropEffect(DragDropEffects effects)
{ {
if (effects.HasFlag(DragDropEffects.Copy)) if (effects.HasFlag(DragDropEffects.Copy))
return new Cursor(StandardCursorType.DragCopy); return StandardCursorType.DragCopy;
if (effects.HasFlag(DragDropEffects.Move)) if (effects.HasFlag(DragDropEffects.Move))
return new Cursor(StandardCursorType.DragMove); return StandardCursorType.DragMove;
if (effects.HasFlag(DragDropEffects.Link)) if (effects.HasFlag(DragDropEffects.Link))
return new Cursor(StandardCursorType.DragLink); return StandardCursorType.DragLink;
return new Cursor(StandardCursorType.No); return StandardCursorType.No;
} }
private void UpdateCursor(IInputElement root, DragDropEffects effect) private void UpdateCursor(IInputElement root, DragDropEffects effect)
@ -98,27 +99,35 @@ namespace Avalonia.Controls.DragDrop
{ {
if (_lastRoot is InputElement ieLast) if (_lastRoot is InputElement ieLast)
{ {
if (_lastCursor == AvaloniaProperty.UnsetValue) if (_originalCursor == AvaloniaProperty.UnsetValue)
ieLast.ClearValue(InputElement.CursorProperty); ieLast.ClearValue(InputElement.CursorProperty);
else else
ieLast.Cursor = _lastCursor as Cursor; ieLast.Cursor = _originalCursor as Cursor;
} }
if (root is InputElement ieNew) if (root is InputElement ieNew)
{ {
if (!ieNew.IsSet(InputElement.CursorProperty)) if (!ieNew.IsSet(InputElement.CursorProperty))
_lastCursor = AvaloniaProperty.UnsetValue; _originalCursor = AvaloniaProperty.UnsetValue;
else else
_lastCursor = root.Cursor; _originalCursor = root.Cursor;
} }
else else
_lastCursor = null; _originalCursor = null;
_lastCursorType = StandardCursorType.Arrow;
_lastRoot = root; _lastRoot = root;
} }
if (root is InputElement ie) if (root is InputElement ie)
ie.Cursor = GetCursorForDropEffect(effect); {
var ct = GetCursorForDropEffect(effect);
if (ct != _lastCursorType)
{
_lastCursorType = ct;
ie.Cursor = new Cursor(ct);
}
}
} }
private void CancelDragging() private void CancelDragging()

Loading…
Cancel
Save